RE: Client Script Question – Remove items from Item sublist which are having unit price has greater than 50 bucks.
This is my code but when i tried to run this code, its now working , in execution log nothing is showing why ? Please help
define(['N/currentRecord'], function(currentRecord) {function sublistChangedRemoveItems(scriptContext) {try {var sublistName = scriptContext.sublistId;// Check if the sublist is the item sublistif (sublistName === 'item') {var currentRecord = scriptContext.currentRecord;var lineCount = currentRecord.getLineCount({sublistId:sublistName});for (var i = lineCount - 1; i >= 0; i--) {var unitPrice = currentRecord.getSublistValue({sublistId: sublistName,fieldId: 'rate',line: i,});// Check if the unit price is greater than 50 bucksif (unitPrice > 50) {log.debug({title: 'Removing item',details: 'Item removed from sublist with unit price greater than 50 bucks',});// Remove the item from the sublistcurrentRecord.removeLine({sublistId: sublistName,line: i,});}}}} catch (e) {log.error({title: "error entry",details: e});}}return {sublistChanged: sublistChangedRemoveItems};});
Please remember that sublistChanged runs whenever you commit a line so it’s unusual to need to loop through the lines in this function.
You may wish to consider:
- Using validateLine to prevent the user entering these lines in the first place.
- Running your check on saveRecord and looping through the lines there.
Thanks,
Chris