This is an entry point in the client script type. In this entry point, the elements in the line items will be validated according to the given code. It defines the validation function that is executed before a line is added to an inline editor sublist or editor sublist. This event can behave like a saveRecord event for line items.
This entry point does have a return value. The return value is a boolean. When the validation conditions are satisfied, it returns true, else false. The return value should be given at the end of the function. Otherwise, the code will not work properly.
The following is a code to validate the line item ‘amount’ in a sales order with the condition amount should be greater than 200 to add to the item line.
function validateLine(scriptContext) {
try{
let currentRecd = scriptContext.currentRecord;
let itemId = currentRecd.getCurrentSublistValue({
sublistId: 'item', fieldId: 'amount'
});
if(itemId <= 200){
alert("The item amount is less than 200.");
return false;
}
return true;
}
catch(e){
log.error(e.message);
}
}
The above code gives an alert message when an item with amount less than 200 is added to the line item.