Marty Zigman Marty Zigman
Prolecto Labs Accelerator Templates

Download a Simple NetSuite Delete Record Script

NetSuite



This article is relevant if you seek to delete records in batch or bulk in NetSuite.

Background

Delete records in NetSuite takes some effort. Thus, we want to be careful when we delete records as there is no easy recovery.   

I have written articles in the past about deleting NetSuite records. See the following articles:

  1. 2009: NetSuite Bulk Delete Record Utility
  2. 2012: Delete NetSuite Records Utilizing Mass Update

Ten years have passed, and it makes sense to show how to craft a straightforward generic Mass Update script using SuiteScript 2.0. 

Simple NetSuite Mass Update Script to Delete Records

The following code pattern will allow you to build a generic NetSuite delete record script. The assumption is that you are a NetSuite Administrator and understand how to set this up. The basic steps are as follows:

  1. Save File to Cabinet: save the script below in a file with a .js file extension to your SuiteScripts cabinet.
  2. Create Mass Update Script: create a saved search definition with reference to your script file. Define the parameter information. 
  3. Deploy the Mass Update Script: deploy the Script definition against the record type you wish to perform delete operations.
  4. Run your Mass Update: run your NetSuite Mass Update against records that you search in your “Custom Update” type. Be careful! There is no undo action on the NetSuite platform.

Click on related images to see how the script definitions should look.

Here is the script:

/*
* Prolecto Resources: this is a generic delete using mass updates 
*/

/**
* @NApiVersion 2.x
* @NScriptType MassUpdateScript
*/

define(['N/record'],
	function(record) {

		var scriptName = "prolecto_MU_GenericDelete.";
		
		function each(params) {
	
			var funcName = scriptName + "each " + params.type + " | " + params.id;
			
			try {
				record.delete({type: params.type, id: params.id});
				log.audit(funcName, "deleted.");
				
			} catch (e) {
	    		log.error(funcName, "Unable to delete: " + e.toString());				
			}
		}

		return {
			each: each
		};
	}
);

Get a NetSuite Utilities Library to Perform Many Scripted Operations   

The above script is a snippet of code we provide as a library of tools to our clients free-of-license charge in our Prolecto Utilities bundle. The Mass Update script is a simple pattern — however, we also supply a similar mechanism using the Map/Reduce scripting pattern. The Map/Reduce pattern is more scalable because it can take advantage of multiple threads and provide a more nuanced way to produce a list of information you can target for record delete operations.

If you found this article relevant, feel free to sign up for notifications to new articles as I post them. If you would like to work with a professional team that can support your NetSuite challenges and would like to take advantage of our license-free intellectual propertylet’s have a conversation.

Marty Zigman

Holding all three official certifications, Marty is regarded as the top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. He is a former Deloitte & Touche CPA and has held CTO roles. For over 30 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to set up a conversation.

More Posts - Website - Twitter - Facebook - LinkedIn - YouTube

About Marty Zigman

Marty Zigman

Holding all three official certifications, Marty is regarded as the top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. He is a former Deloitte & Touche CPA and has held CTO roles. For over 30 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to set up a conversation.

Biography • Website • X (Twitter) • Facebook • LinkedIn • YouTube

8 thoughts on “Download a Simple NetSuite Delete Record Script

  1. Kane says:

    Nice! I made my own similar mass-delete script but I used a scheduled script and added in a fail-safe “just in case.”
    Basically I have a checkbox script parameter on the deployment called “Run Deletion” and my script deletes only about 20 records at a time before re-scheduling itself.
    Each time the script starts it checks if the “Run Deletion” parameter is still true, and if it’s not it terminates.

  2. Marty Zigman says:

    Thank you Kane. We do something similar with our Map/Reduce by ensuring that an app.setting is properly set.

    Marty

  3. Sean says:

    Not sure if my last message went through. In short, we have a fairly complex set of record types that are linked in a parent child relationship some a few levels deep. We want to find a way to delete all of the records but run into the dependent record issue when we do it manually. The issue is it is very hard to identify the lowest child and then work our way up. I was wondering if this script would delete records that may have linked record types?

  4. Marty Zigman says:

    Hello Sean,

    Indeed, we have built recursive delete routines. You need a craft a map to navigate the record types to understand how to get the child records first. Thus it is not “simple.” If you would like a specialized version to delete NetSuite child records, reach out to me.

    Marty

  5. Rebecca says:

    I used this to delete GL transactions that were mistakenly imported. It works for credit card charges and credit card payments, but checks, deposits, and bill payments won’t show up on the list in custom updates. How can you use this to delete checks or deposits?

  6. Marty Zigman says:

    Hello Rebecca,

    Did you deploy the script to those record types and make sure you a) release the script and b) make it public? This should help it show up.

    Marty

  7. Joe says:

    Will this work to delete specific sublist records. In particular certain customer addresses we no longer need/want?

  8. Marty Zigman says:

    Hello Joe,

    No, this generic algorithm will need to enhanced for subsists based deletes. If you need help crafting one, our team can assist. Contact us here: https://www.prolecto.com/contact-us/

    Marty

Leave a Reply

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