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:
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:
- Save File to Cabinet: save the script below in a file with a .js file extension to your SuiteScripts cabinet.
- Create Mass Update Script: create a saved search definition with reference to your script file. Define the parameter information.
- Deploy the Mass Update Script: deploy the Script definition against the record type you wish to perform delete operations.
- 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 property, let’s have a conversation.
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.
Thank you Kane. We do something similar with our Map/Reduce by ensuring that an app.setting is properly set.
Marty
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?
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
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?
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
Will this work to delete specific sublist records. In particular certain customer addresses we no longer need/want?
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