User Event Scripts as XML Definitions
You can import user event scripts from a target NetSuite account into your SuiteCloud projects. User event scripts are triggered on the NetSuite server when a user performs certain actions on a record. These actions are called user events and can occur when a user creates, loads, updates, copies, deletes or submits a record. For more information about user event scripts, see SuiteScript 2.x User Event Script Type.
You can create a user event script for a NetSuite account using SuiteCloud Development Framework (SDF) by creating a usereventscript
SDF custom object in a SuiteCloud project and then deploying it to a target account. You can also import a user event script 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.
Components of a Script Object
There are three components that are required for the script object:
-
The Scriptid Attribute: Provide a readable
scriptid
attribute for the script record andscriptdeployment
structure by adding an underscore to the default value followed by a meaningful name for the object. The script record’sscriptid
attribute must start with acustomscript_
prefix and eachscriptdeployment
structure’sscriptid
attribute 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
scriptdeployments
structure. A script object may contain multiple script deployments.
Components of a User Event Script Object
The user event script object has two important components that allow it to work:
-
The Script Record-Represented in XML by the
usereventscript
SDF custom object. This object contains several elements that define it, including the name of the user event script object and a reference to the location of the user event script file. The following example shows ausereventscript
object named “User Event Example” that references a user event script file named“UserEventScript.js”
.<usereventscript scriptid="customscript_userevent_example"> <name>User Event Example</name> <notifyowner>T</notifyowner> <scriptfile>[/SuiteScripts/UserEventScript.js]</scriptfile> <scriptdeployments> <scriptdeployment scriptid="customdeploy_userevent_example"> <isdeployed>T</isdeployed> <loglevel>DEBUG</loglevel> <recordtype>[customrecord_userevent_example]</recordtype> <status>TESTING</status> </scriptdeployment> </scriptdeployments> </usereventscript>
-
The Script Deployment Record-Represented by the
scriptdeployments
structure. It is contained within theusereventscript
object where you can define certain values such as the record type and status. The following example shows therecordtype
element referencing a custom record named“customrecord_userevent_example”
. Thestatus
element has a value set to “TESTING”. This example only has one script deployment, but a user event script object may contain multiple script deployments.<usereventscript scriptid="customscript_userevent_example"> <name>User Event Example</name> <notifyowner>T</notifyowner> <scriptfile>[/SuiteScripts/UserEventScript.js]</scriptfile> <scriptdeployments> <scriptdeployment scriptid="customdeploy_userevent_example"> <isdeployed>T</isdeployed> <loglevel>DEBUG</loglevel> <recordtype>[customrecord_userevent_example]</recordtype> <status>TESTING</status> </scriptdeployment> </scriptdeployments> </usereventscript>
For more information about:
-
usereventscript
object fields and possible values, see usereventscript. -
scriptdeployment
structure fields and possible values, see scriptdeployment. -
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 thestatus
element. 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 User Event Script Object
Provide a readable scriptid
attribute for the usereventscript
object and scriptdeployment
structure by adding an underscore to the default value followed by a meaningful name for the object. The usereventscript
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 usereventscript
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 user event script deploys to the correct record. -
status
-Provide a value for thestatus
element. The default value is TESTING. Possible values are:-
COMPLETED
-
INPROGRESS
-
INQUEUE
-
NOTSCHEDULED
-
RELEASED
-
SCHEDULED
-
TESTING
-
Example of a User Event Script Object
The following example shows a usereventscript
object containing multiple scriptdeployments
.
<usereventscript scriptid="customscript_userevent_example">
<name>User Event Example</name>
<notifyowner>T</notifyowner>
<scriptfile>[/SuiteScripts/UserEventScript.js]</scriptfile>
<scriptdeployments>
<scriptdeployment scriptid="customdeploy_userevent_example">
<isdeployed>T</isdeployed>
<loglevel>DEBUG</loglevel>
<recordtype>[customrecord_userevent_example]</recordtype>
<status>TESTING</status>
</scriptdeployment>
<scriptdeployment scriptid="customdeploy_test1">
<isdeployed>T</isdeployed>
<loglevel>DEBUG</loglevel>
<recordtype>[customrecord_test1]</recordtype>
<status>TESTING</status>
</scriptdeployment>
<scriptdeployment scriptid="customdeploy_test2">
<isdeployed>T</isdeployed>
<loglevel>DEBUG</loglevel>
<recordtype>[customrecord_test2]</recordtype>
<status>TESTING</status>
</scriptdeployment>
</scriptdeployments>
</usereventscript>
Related Topics
- Scripting
- 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
- Mass Update Scripts as XML Definitions
- Suitelet Scripts as XML Definitions
- RESTlet Scripts as XML Definitions
- Secrets as XML Definitions
- Single Page Applications as XML Definitions