SuiteScript 2.x Mass Update Script Type
Mass update scripts allow you to programmatically perform custom updates to fields that are not available through general mass updates. These scripts can perform complex calculations across multiple records, based on your script. You can run mass update scripts on demand, but you can't prioritize or schedule them for specific times. If you need to run a script at a specific time, look into using a scheduled or map/reduce script instead. For more information, see SuiteScript 2.x Scheduled Script Type and SuiteScript 2.x Map/Reduce Script Type.
When you click Perform Update button on the Mass Update Preview Results page, the script runs on the server. You can't run a mass update script from within another type of script. You also cannot programmatically check the status of a mass update script or determine when the script started or ended.
Keep the following things in mind when running a mass update script:
-
When you run a custom mass update, it can trigger user event scripts if they're associated with the records you're updating.
-
You can assign an audience to both mass update script deployments and mass updates. The script owner must make sure the audiences match. If the audiences don't match, the script won't run when users click the Perform Update button on the Mass Update page.
-
To run a custom mass update, users need the right permission (Edit or Full) for the record type they're updating.
-
Users must also have SuiteScript enabled in their accounts. (Administrators can go to Setup > Company > Enable Features. In the SuiteCloud tab, click the Server SuiteScript box and the Client SuiteScript box.)
For information about scripting with mass update scripts, see SuiteScript 2.x Mass Update Script Entry Points and API.
SuiteCloud Development Framework (SDF) lets you manage mass update scripts as part of your file-based customization projects. For information about SDF, see SuiteCloud Development Framework. The Copy to Account feature lets you copy a mass update script to another account. You'll find the Copy to Account option on the top right of each mass update script page. For information about Copy to Account, see Copy to Account.
SuiteScript Analysis helps you understand when a script was installed and how it's performed over time. For more information, see Analyzing Scripts.
Mass Update Script Sample
This code updates the probability field of all existing records to 61%.
From the script deployment record, ensure that the Applies To field is set to Opportunity.
For help with writing scripts in SuiteScript 2.x, see SuiteScript 2.x Hello World and SuiteScript 2.x Entry Point Script Creation and Deployment.
/**
*@NApiVersion 2.1
*@NScriptType MassUpdateScript
*/
define(['N/record'], (record) => {
function each(params) {
// Set the probability to 61%
let recOpportunity = record.load({
type: params.type,
id: params.id
});
recOpportunity.setValue('probability', 61);
recOpportunity.save();
}
return {
each: each
};
});
Related Support Article
Related Topics
- SuiteScript 2.x Script Types
- SuiteScript 2.x Bundle Installation Script Type
- SuiteScript 2.x Client Script Type
- SuiteScript 2.x Map/Reduce Script Type
- SuiteScript 2.x Portlet Script Type
- SuiteScript 2.x RESTlet Script Type
- SuiteScript 2.x Scheduled Script Type
- SuiteScript 2.x Suitelet Script Type
- SuiteScript 2.x User Event Script Type
- SuiteScript 2.x Workflow Action Script Type