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!

aleseux Rookie Asked on November 14, 2022 in SuiteScript.
Add Comment
2 Answers

Thanks, George! Opted for the second and it works swimmingly.

Rookie Answered on November 14, 2022.

Glad I could help 🙂

on November 14, 2022.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.