Mass Delete Script

Deleting transactions is always frowned upon from a compliance perspective, but sometimes there is a valid reason for doing so. Perhaps the client hasn’t invested in a sandbox which has caused testing and training to be performed in the production environment. I had a similar situation for a project in 2018 that required me to delete a large number of work orders and their related issue, completion and close records, and thankfully I had kept hold of this script that allowed me trigger the deletion of my records while I went and made a cup of tea.

Once created as a mass update script, simply deploy the script for the transaction types you wish to delete and you’re on your way. Below are the step-by-step guides to create the script and deploying it successfully to run.

Copy the following code, copy it to a notepad file, and save it as a .js file.

function massDelete(rec_type, rec_id)
try {
nlapiDeleteRecord(rec_type, rec_id);
nlapiLogExecution (‘DEBUG’, rec_id + ‘ was deleted successfully’);
catch(e) {
nlapiLogExecution (‘DEBUG’, rec_id + ‘ was not deleted\n’ + e);

Login to NetSuite, and create a new script (Customization > Scripting > Scripts > New).

Select the .js file you created using the code snippet above and click Create Script Record.

Select Mass Update as the script type.

Set the Function field to ‘massDelete’, as referenced in the first line of the code snippet.

Give the Script a Name and then press Save and Deploy.

Set the Status to ‘Released’, Execute Role as ‘Administrator’ and select the transaction you’d like the script to run on, ie. what transactions would you like to delete. Press Save.

Create a new Mass Update (Lists > Mass Update > Mass Updates).

Expand the Custom Updates menu near the bottom of the list and select your Mass Delete update on the transaction type you deployed it on.

Enter any criteria you’d like to filter the transactions by in case there are only specific transactions you’d like to delete.

Press Preview.

Press Perform Update.

The script will run through all of the records that matched your criteria, and will be deleted unless there are any dependant records or any other issues. It’s always best practice to run a new search with the same criteria you selected on the mass update to ensure everything you expected to be gone has been deleted.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s