Mass Deletion of Records


The best practice with NetSuite in regards to record deletion is generally to inactivate the record and avoid actual deletion. There are times when circumstances do justify the deletion of records. If there are more than several dozen records, it can be a time consuming and tedious series of clicks to delete manually. You can easily perform a mass delete by leveraging the mass update feature. This approach is simple by taking the complexity out of the code that might have been written and places control into the hands of the user. When the user sets up their mass update, they can control, using the saved search as criteria, which records to operate on. There is also a chance to preview the list of records before executing the update. Once the user is comfortable with the list they can perform the update. NetSuite will then loop through each record in the list and pass the record type and id to the custom script. This approach takes only a single line of code.

Step 1: Create a Mass Update SuiteScript that looks like this:

Function delete_records(recordType, recordID)
nlapiDeleteRecord(recordType, recordID); // Delete record

Step 2: Register your script in NetSuite:

a) Select the Script type:

Tip Image 1
Click image to enlarge

b) Register your script:

Tip Image 2
Click image to enlarge

c) Deploy the script for each record type you plan on deleting

Tip Image 3
Click image to enlarge

Step 3: Execute your mass delete by going to the mass update screen and look under Custom Updates.
Your list of script deployments will be listed by record type. The rest of the mass update process has not changed.

Tip Image 4
Click image to enlarge