Saturday, March 30, 2019

Steps to Disable Line Item Field for a Single Line of a Sublist using SuiteScript

The following client-side script is showing how to disable a field for a specific line, and not for the whole column which is default behavior of nlapiDisableLineItemField function.
It is useful e.g. to disallow a user to enter value if certain conditions on specific lines are met.

The sample script below disables Description column field only on the second line on Items sublist.

function disableLineField(type) {	if (type != "item")		return;		// Exit the function if we are not on the sublist		// with internal ID "item" where we want to disable the field	// Change this to number of line where the field should be disabled	var lineToDisable = 2;	var selectedLine = nlapiGetCurrentLineItemIndex(type);	if (selectedLine == lineToDisable) {		nlapiDisableLineItemField(type, "description", true);	} else {		// allow user to enter value if we are not at that specific line		nlapiDisableLineItemField(type, "description", false);	}}

The script is deployed as a client-side script on a record where we want to disable a field.
The function is best triggered using Line Init function todisable the field while switching between lines.

No comments:

Post a Comment