When dealing with high-volume data accounts, regular data cleanup becomes essential. Whether you're cleaning up your development account after performance testing or consolidating data from multiple instances during a company merger or acquisition, knowing how to mass delete records in NetSuite is invaluable. However, it's important to note that the methods outlined here are effective only for records that do not have dependencies. For example, if a sales order has related transactions such as invoices, you'll need to delete these related invoices first before you can remove the sales order. Ensure that all dependent records are removed before proceeding with the mass deletion to avoid errors.
Yes! You can mass delete via the user interface, but there are a few prerequisites to meet first.
Once the prerequisites are satisfied, follow these steps:
Here’s a video demonstrating these steps: Mass-Deleting-Records-via-UI
1/**
2 * @NApiVersion 2.1
3 * @NScriptType MassUpdateScript
4 * @NModuleScope SameAccount
5 */
6
7import {EntryPoints} from "N/types";
8
9import * as record from "N/record";
10
11export const each: EntryPoints.MassUpdate.each = (({type, id}) => {
12 record.delete({
13 type,
14 id
15 });
16});
1/**
2 * @NApiVersion 2.1
3 * @NScriptType WorkflowActionScript
4 * @NModuleScope SameAccount
5 */
6
7import {EntryPoints} from "N/types";
8
9import * as record from "N/record";
10
11export const onAction: EntryPoints.WorkflowAction.onAction = (({newRecord}) => {
12 const {type, id} = newRecord;
13 record.delete({
14 type,
15 id
16 });
17});
1/**
2 * @NApiVersion 2.1
3 * @NScriptType MapReduceScript
4 * @NModuleScope SameAccount
5 */
6
7import {EntryPoints} from "N/types";
8
9import * as record from "N/record";
10import * as runtime from "N/runtime";
11import * as search from "N/search";
12
13export const getInputData: EntryPoints.MapReduce.getInputData = () => {
14 const currentScript = runtime.getCurrentScript();
15
16 const RECORDS_TO_DELETE_SEARCH = "custscript_asp_records_to_delete";
17 const savedSearchId = currentScript.getParameter({
18 name: RECORDS_TO_DELETE_SEARCH
19 }) as string;
20
21 return search.load({
22 id: savedSearchId
23 });
24};
25
26export const map: EntryPoints.MapReduce.map = (scriptContext) => {
27 const {key: id, value} = scriptContext;
28 const type = JSON.parse(value).recordType;
29
30 record.delete({
31 type,
32 id
33 });
34};
The best method depends on your needs. If you need to quickly delete a few records, the record list UI is your go-to. For handling large volumes of data with more flexibility, consider mass updates, workflow actions, or Map/Reduce scripts.
To see the complete SuiteScript code and implementation details discussed in this article, visit Jona's GitHub repository.
Jona has over a decade of experience in SuiteCloud Development on the NetSuite platform. She specializes in implementing advanced solutions and has led teams in creating high-quality software. Jona holds multiple certifications and has been recognized with awards like the Summit Award and Quality Champion Award.