Removing Items from Sublist

When removing lines from a sublist with SuiteScript, it’s best to work your way up from the bottom of the list.

Removing the first line item, for example, changes the index value for all of the other line items. Then, trying to remove the line with the index count gives you SSS_INVALID_SUBLIST_OPERATION because a line with that index no longer exists.

sample code: Sample client script for removing item lines.

var curRec = currentRecord.get();

//get line count
var lineCount = curRec.getLineCount({
sublistId: 'item'
});
// removing items from the list
for (var j = lineCount - 1; j >= 0; j--) {
try {
var itemType = curRec.getSublistValue({
sublistId: 'item',
fieldId: 'itemtype',
line: j
});
var newItemId = curRec.getSublistValue({
sublistId: 'item',
fieldId: 'item',
line: j
});
if (itemType == 'EndGroup') continue;
newitemList.push(newItemId);
removeLineItem(curRec, j);
} catch (e) {
console.error("error@removal", e);
}
}

Leave a comment

Your email address will not be published. Required fields are marked *