Client Scripts as XML Definitions
You can import client scripts from a target NetSuite account into your SuiteCloud projects. Client Scripts are generally used to validate user-entered data, and to auto-populate fields or sublists when triggered by various form events.
There are 12 client event types that can trigger the execution of your client scripts:
-
pageInit
-
saveRecord
-
validateField
-
fieldChanged
-
postSourcing
-
lineInit
-
validateLine
-
recalc
-
validateInsert
-
validateDelete
-
localizationContextEnter
-
localizationContextExit
You can create a client script object in your SuiteCloud project and deploy it to a target NetSuite account. A client script can also be imported from a NetSuite account into your SuiteCloud project.
For more information, see:
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 Client Script Object
The following components allow the portlet object to work.
-
The Script Record: Represented in XML by the
clientscript
object. The object contains several elements that define it, including the name of theclientscript
object, and a reference to the location of the client script file. The following example shows aclientscript
object named“Client Script Example”
that references a client script file named“ClientScriptExample.js”
.<clientscript scriptid="customscript_clientscript_example"> <isinactive>T</isinactive> <name>Client Script Example</name> <notifyowner>T</notifyowner> <scriptfile>[/SuiteScripts/ClientScriptExample.js]</scriptfile> <scriptdeployments> <scriptdeployment scriptid="customdeploy_clientscript_example"> <isdeployed>T</isdeployed> <loglevel>DEBUG</loglevel> <recordtype>TASK</recordtype> <status>TESTING</status> </scriptdeployment> </scriptdeployments> </clientscript>
-
The Script Deployment Record: Represented in XML by the
scriptdeployments
structure. It is contained within theclientscript
object where you can define certain values such as therecordtype
andstatus
. the following example shows therecordtype
element referencing a custom record named“TASK”
. Thestatus
element is set to“TESTING”
. This example only has one script deployment, but a client script object may contain multiple script deployments.<clientscript scriptid="customscript_clientscript_example"> <isinactive>T</isinactive> <name>Client Script Example</name> <notifyowner>T</notifyowner> <scriptfile>[/SuiteScripts/ClientScriptExample.js]</scriptfile> <scriptdeployments> <scriptdeployment scriptid="customdeploy_clientscript_example"> <isdeployed>T</isdeployed> <loglevel>DEBUG</loglevel> <recordtype>TASK</recordtype> <status>TESTING</status> </scriptdeployment> </scriptdeployments> </clientscript>
For more information about:
-
The steps needed to run your client script in the NetSuite UI, see SuiteScript 2.x Client Script Type
-
Client script samples, see Client Script Samples
-
Attaching your client script to a form, see Attaching a Client Script to a Form
-
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 Client Script Object
Provide a readable scriptid
attribute for the clientscript
object and scriptdeployment
structure by adding an underscore to the default value followed by a meaningful name for the object. The clientscript
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 clientscript
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 client 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
-
For more information about:
-
clientscript
object fields and possible values, see clientscript -
scriptdeployments
structure fields and possible values, see scriptdeployment
Example of a Client Script Object
The following example shows the client script file named “ClientScriptExample.js”
that is being referenced in the client script object. This client script is using the pageInit
function to display a title and message before the form is first loaded.
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define(['N/ui/dialog'],
function(dialog) {
function helloWorld() {
var options = {
title: 'Hello!',
message: 'Hello, world!'
};
try {
dialog.alert(options);
log.debug({
title: 'Success',
details: 'Alert displayed successfully'
});
} catch (e) {
log.error({
title: e.name,
details: e.message
});
}
}
return {
pageInit: helloWorld
};
}
);
The following example shows a client script object referencing the “ClientScriptExample.js”
file:
<clientscript scriptid="customscript_clientscript_example">
<isinactive>F</isinactive>
<name>Client Script Example</name>
<notifyowner>T</notifyowner>
<scriptfile>[/SuiteScripts/ClientScriptExample.js]</scriptfile>
<scriptdeployments>
<scriptdeployment scriptid="customdeploy_clientscript_example">
<isdeployed>T</isdeployed>
<loglevel>DEBUG</loglevel>
<recordtype>TASK</recordtype>
<status>TESTING</status>
</scriptdeployment>
</scriptdeployments>
</clientscript>
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
- 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