How to use a client script to identify deleted items in NetSuite.

We can identify the operation of the line level in the client script’s sublistChanged trigger.

Using this facility, identify the operation equal to remove while also getting the line unique key; if both operations are removedĀ and the line unique key is not empty, the item has been removed from the items sublist.

Get the item name from the current sublist and save it in an array so that you can identify the deleted items in the array.

/**
 * Client script sublistChanged event handler
 */
function sublistChanged(scriptContext) {
  var currentRecord = scriptContext.currentRecord;
  var sublistName = scriptContext.sublistId;

  // Check if the sublist is the items sublist
  if (sublistName === 'item') {
    var operation = currentRecord.getCurrentSublistValue({
      sublistId: sublistName,
      fieldId: 'custcol_operation' // Assuming there is a custom field to track the operation
    });
    var lineUniqueKey = currentRecord.getCurrentSublistValue({
      sublistId: sublistName,
      fieldId: 'lineuniquekey' // Assuming there is a unique identifier field for each line
    });

    // Check if the operation is 'remove' and line unique key is not empty
    if (operation === 'remove' && lineUniqueKey) {
      var itemName = currentRecord.getCurrentSublistText({
        sublistId: sublistName,
        fieldId: 'item'
      });

      // Store the item name in an array or perform any required logic
      var deletedItems = [];
      deletedItems.push(itemName);
    }
  }
}


return {
sublistChanged: sublistChanged
};

Leave a comment

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