Marty Zigman

Conversations with Marty Zigman

Certified Administrator • ERP • SuiteCloud

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 LinkedIn

Marty Zigman

Holding three official certifications, Marty is widely recognized as a top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. A former Deloitte & Touche CPA and technology executive with CTO roles, he brings over 35 years of leadership in ERP, CRM, and eCommerce business systems. Contact Marty to engage directly.

BiographyYouTubeLinkedInX (Twitter)

8 thoughts on “Download a Simple NetSuite Delete Record Script

  1. 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.

    Reply
  2. 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?

    Reply
  3. 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?

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

    Reply

Leave a Reply

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