RE: SuiteScript: Trigger to Delete Sublist Line After Another is Deleted
I’m working on a Client Script for managing product UPCs. One of the pieces of this is to delete additional lines from a sublist if one with certain criteria is deleted.
Currently, I’m using validateDelete to search the remaining items in the sublist and delete any that meet the criteria. The issue is that I’m causing an infinite loop as every time I try to delete another line it kicks off validateDelete again.
Code:
function validateDelete(scriptContext) { const delRecord = scriptContext.currentRecord; const delSublist = scriptContext.sublistId; if (delSublist === primaryListID) { const delValue = delRecord.getCurrentSublistValue({ sublistId: delSublist, fieldId: primaryFieldID }); const otherExists = delRecord.findSublistLineWithValue({ sublistId: delSublist, fieldId: primaryFieldID, value: UPCmod.checkDigit(delValue) }); if (otherExists !== -1){ delRecord.removeLine({ sublistId: delSublist, line: otherExists, ignoreRecalc: true }); } return true; } }
Any ideas for me? I couldn’t puzzle through getting fieldChanged to trigger on a sublist line being deleted, so that’s why I landed on validateDelete. I had hoped ignoreRecalc would do the trick, but it didn’t seem to make any difference.
Thank you!
Thanks, George! Opted for the second and it works swimmingly.
Glad I could help 🙂