Mass Update Scripts as XML Definitions
You can import mass update scripts from a target NetSuite account into your SuiteCloud projects for SuiteCloud Development Framework (SDF). Mass update scripts let you perform custom updates to fields that are unavailable through general mass updates. You can also customize mass update scripts to run complex calculations across many records. For more information, see SuiteScript 2.x Mass Update Script Type.
The mass update script object can be created in your SuiteCloud project and deployed to a target NetSuite account. Mass update scripts can also be imported from a NetSuite account into your SuiteCloud project. For information about importing SDF custom objects, files, and scripts from a NetSuite account into your SuiteCloud project, see Account Component Imports to SuiteCloud Projects.
For information about working with a mass update script object from your SuiteCloud project, see the following topics:
Components of a Script Object
There are three components that are required for the script object:
-
The Scriptid Attribute: Provide a readable
scriptidattribute for the script record andscriptdeploymentstructure by adding an underscore to the default value followed by a meaningful name for the object. The script record’sscriptidattribute must start with acustomscript_prefix and eachscriptdeploymentstructure’sscriptidattribute must start with acustomdeploy_prefix. -
The Script Record: Represented in XML by the object. The object contains several elements that define it, including the object name and a reference to the location of the script file.
-
The Script Deployment Record: Represented in XML by the
scriptdeploymentsstructure. A script object may contain multiple script deployments.
Components of a Mass Update Script Object
The following components allow the massupdatescript to work:
-
The Script Record: Represented in XML by the
massupdatescriptobject. The object contains several elements that define it, including the name of themassupdatescriptobject, and a reference to the location of the mass update script file. The following example shows amassupdatescriptobject named “Mass Update Test” that references a mass update script file named “MassUpdateScripttest.js”.<massupdatescript scriptid="customscript_massupdate_test"> <defaultfunction>testMassUpdate</defaultfunction> <name>Mass Update Test</name> <notifyowner<T>/notifyowner> <scriptfile>[/SuiteScripts/MassUpdateScripttest.js]</scriptfile> <scriptdeployments> <scriptdeployment scriptid="customdeploy_massupdate_test"> <isdeployed>T</isdeployed> <loglevel>DEBUG</loglevel> <recordtype>[customrecord_massupdate_test]</recordtype> <status>TESTING</status> </scriptdeployment> </scriptdeployments> </massupdatescript> -
The Script Deployment Record: Represented in XML by the
scriptdeploymentsstructure. It is contained within themassupdatescriptobject where you can define values such as therecordtypeandstatus. The following example shows therecordtypeelement referencing a custom record named“customrecord_massupdate_test”. The status element has a value set to “TESTING”. This example only has one script deployment, but a mass update script object may contain multiple script deployments.<massupdatescript scriptid="customscript_massupdate_test"> <defaultfunction>testMassUpdate</defaultfunction> <name>Mass Update Test</name> <notifyowner<T>/notifyowner> <scriptfile>[/SuiteScripts/MassUpdateScripttest.js]</scriptfile> <scriptdeployments> <scriptdeployment scriptid="customdeploy_massupdate_test"> <isdeployed>T</isdeployed> <loglevel>DEBUG</loglevel> <recordtype>[customrecord_massupdate_test]</recordtype> <status>TESTING</status> </scriptdeployment> </scriptdeployments> </massupdatescript>
For more information about:
-
The available
massupdatescriptobject fields and possible values, see massupdatescript. -
The available
scriptdeploymentstructure fields and possible values, see scriptdeployment. -
Running a Mass Update Script using the NetSuite UI, see SuiteScript 2.x Mass Update Script Type.
-
Creating a generic script record in a NetSuite account, see Creating a Script Record.
-
Creating a deployment record in a NetSuite account, see Deploying a Script by using the Deployments Sublist.
Setting Values for a Script Object
Each script object has a set of values that are required to successfully validate its script record and script deployment record.
The following elements are required to successfully validate your script record:
-
name—Provide a meaningful name for your script record. -
scriptfile—Reference the appropriate script file. This must be a JavaScript file (.js).
The following element is required to successfully validate your script deployments:
-
status—Provide a value for thestatuselement. The default value is TESTING. The only values accepted for all scripts except scheduled scripts are:-
RELEASED: The script will run in the accounts of all specified audience members.
-
TESTING: The script will execute for the script owner and specified audience.
The remaining possible values for the status element are:
-
COMPLETED
-
INPROGRESS
-
INQUEUE
-
NOTSCHEDULED
-
SCHEDULED
-
Setting Values for a Mass Update Script Object
Provide a readable scriptid attribute for the massupdatescript object and scriptdeployment structure by adding an underscore to the default value followed by a meaningful name for the object. The massupdatescript object’s scriptid attribute must start with a “customscript_” prefix and each scriptdeployment structure’s scriptid attribute must start with a “customdeploy_” prefix.
The following elements are required to successfully validate a massupdatescript object:
-
name—Provide a meaningful name for your script record. -
scriptfile—Reference the appropriate script file. This must be a JavaScript file (.js).
The following elements are required to successfully validate a scriptdeployment structure:
-
recordtype—Reference the appropriate record within your deployment script so that your mass update script deploys to the correct record. -
status—Provide a value for thestatuselement. The default value is TESTING. Possible values are:-
RELEASED: The script will run in the accounts of all specified audience members.
-
TESTING: The script will execute for the script owner and specified audience.
-
Example of a Mass Update Script Object
The following example shows a mass update script object referencing the MassUpdateScripttest.js file. The object’s script record is named Mass Update Test with a scriptid attribute of customscript_massupdate_test.
<massupdatescript scriptid="customscript_massupdate_test">
<defaultfunction>testMassUpdate</defaultfunction>
<name>Mass Update Test</name>
<notifyowner<T>/notifyowner>
<scriptfile>[/SuiteScripts/MassUpdateScripttest.js]</scriptfile>
<scriptdeployments>
<scriptdeployment scriptid="customdeploy_massupdate_test">
<isdeployed>T</isdeployed>
<loglevel>DEBUG</loglevel>
<recordtype>[customrecord_massupdate_test]</recordtype>
<status>TESTING</status>
</scriptdeployment>
</scriptdeployments>
</massupdatescript>
The following example shows a mass update script file named MassUpdateScripttest.js that is being referenced in the mass update script object. This script implements a mass update to set the probability field of all existing records to 61%.
/**
*@NApiVersion 2.x
*@NScriptType MassUpdateScript
*/
define(['N/record'],
function(record) {
function each(params) {
// Set the probability to 61%
var recOpportunity = record.load({
type: params.type,
id: params.id
});
recOpportunity.setValue('probability', 61);
recOpportunity.save();
}
return {
each: each
};
});
Related Topics
- Scripting
- User Event Scripts as XML Definitions
- Scheduled Scripts as XML Definitions
- SDF Installation Scripts as XML Definitions
- Workflows as XML Definitions
- Translation Collections as XML Definitions
- Map/Reduce Script Objects as XML Definitions
- Portlet Scripts as XML Definitions
- Client Scripts as XML Definitions
- Integration Records as XML Definitions
- Suitelet Scripts as XML Definitions
- RESTlet Scripts as XML Definitions
- Secrets as XML Definitions
- Single Page Applications as XML Definitions
- Custom Tool Scripts as XML Definitions