Back to Blogs
NetSuite Diaries

From Clutter to Clarity: How to Mass Delete Records in NetSuite

Jona Obrador
September 11, 2024
6
minutes to read

How to Mass Delete Records in NetSuite

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.

1. Using the Record List UI

Yes! You can mass delete via the user interface, but there are a few prerequisites to meet first.

Prerequisites

  1. Set up the record for inline editing.
  2. Ensure there is a field that can be inline edited, such as the name field. Inline editable fields are represented by a pencil icon when viewing the list of records.

enable-inline-editing
Enable inline editing.

Perform Mass Deletion

Once the prerequisites are satisfied, follow these steps:

  1. Navigate to the records list.
  2. Enable inline editing by toggling the “Edit” option beside the “Show Inactives” checkbox.
  3. Click on the editable field of the record to be deleted.
  4. Hold Shift and click on the last record on the list.
  5. Press Delete; a confirmation dialog appears.
  6. Click OK.
records-for-deletion-from-list
Highlight the records for deletion.

Here’s a video demonstrating these steps: Mass-Deleting-Records-via-UI


2. Using Mass Update Script

Prerequisites

  1. Create a mass update script that deletes the records.
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. Deploy the script on the records to be deleted.
mu-deployment
Mass Update script deployment.

Execute Mass Update Script

  1. Create a Mass Update
  • Navigate to Lists > Mass Update > Mass Updates
  • The created mass update script deployment will be available under Custom Updates.

mass-update-action

  • Click on the created mass update script deployment
  • Click “Save”
mu-criteria
On this page, you can set the criteria to determine which records should be deleted.

  1. Perform Mass Update
    • Navigate to Lists > Mass Update > Saved Mass Updates
    • Click “Preview” of the created Mass Update
    • Click "Perform Update".
mu-trigger-deletion
Record results for deletion.

3. Using Workflow Action Script

Prerequisites

  1. Create a workflow action script that deletes the records.
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. Deploy the script on the records to be deleted.
wa-deployment
Workflow Action script deployment.

  1. Create a saved search for the records to be deleted (ensure there is at least one criteria).
wa-search-criteria
Saved search criteria for deletion.

Execute Workflow Action Script

  1. Create a Workflow
    • Navigate to Customization > Workflow > Workflows > New.
    • Set Record Type to the record you want to delete.
    • Set Initiation to Scheduled.
    • Choose the saved search you created under Saved Search Filter.
    • Uncheck "repeat" to prevent re-execution.

wa-workflow

  1. Create a Workflow Action in Statesome text
    • Select the state and click “New Action”.

wa-action-new

  • Create a state action using the deployed workflow action script.
wa-action-setup

  1. Execute Workflow
    • Navigate back to Workflow
    • Schedule or execute it immediately. To execute immediately, ensure Release Status is “Testing” and click “Execute Now”.

wa-action-execute


4. Using Map/Reduce Script

Prerequisites

  1. Create a Map/Reduce script that deletes the records.
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};

  1. Include a parameter “Records to Delete Search” in the script record to allow dynamic input on which records to delete.
mu-parameter
  1. Create a saved search for the records to be deleted.
mu-search

Execute Map/Reduce Script

  1. Deploy the created script
  2. Set the saved search you created in the “Records to Delete Search” parameter.
mr-deployment

  1. Schedule or execute it immediately. To execute immediately, ensure Status is “Not Scheduled” and click “Save & Execute”.
mr-trigger

Final Thoughts

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.


Meet the Author

jona-obrador-author

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.