UI and Record Script Type Differences
Client, portlet, Suitelet, user event, and workflow action scripts respond to user-interface, record, or workflow activity.
The following sections compare these script types in SuiteScript 1.0 and SuiteScript 2.1:
Client Script Type Differences
When you convert a client script from SuiteScript 1.0 to 2.1, these event names and arguments change:
-
The SuiteScript 1.0
pageInitargumenttypecorresponds to the SuiteScript 2.1 context propertymode. -
For
fieldChangedandvalidateField, the SuiteScript 1.0type,name, andlinenumarguments correspond to the SuiteScript 2.1sublistId,fieldId, andlineproperties, respectively. -
For sublist fields, SuiteScript 1.0
linenumstarts at 1, while SuiteScript 2.1linestarts at 0. Adjust line-number logic when converting these scripts. -
The SuiteScript 1.0
recalcevent corresponds to the SuiteScript 2.1sublistChangedentry point.
SuiteScript 2.1 also adds these context properties and entry points:
-
Client script entry point context objects include the
currentRecordproperty. -
The context objects passed to the
fieldChangedandvalidateFieldentry points include thecolumnproperty. -
The context object passed to the
validateDeleteentry point includes thelineCountproperty. -
Client scripts include the
localizationContextEnterandlocalizationContextExitentry points.
SuiteScript 2.1 client scripts run in the browser. Use JavaScript features supported by your users' browsers.
For more information about the client script type in SuiteScript 2.1, see SuiteScript 2.1 Client Script Type.
Portlet Script Type Differences
At the script level, portlets differ between SuiteScript 1.0 and 2.1 in these ways:
-
In SuiteScript 2.1, a portlet script includes the
renderentry point. There is no equivalent event type in SuiteScript 1.0. -
In SuiteScript 1.0, NetSuite passes the portlet object and dashboard column index as separate arguments to the portlet function. In SuiteScript 2.1, the
renderentry point receives them throughparams.portletandparams.column.
On the SuiteScript 2.1 Portlet object, these methods and properties change:
-
The SuiteScript 1.0
nlobjPortlet.setRefreshInterval(n)method is not available on the SuiteScript 2.1Portletobject. -
The SuiteScript 1.0
nlobjPortletmethodssetHtml(html)andsetTitle(title)correspond to the SuiteScript 2.1Portlet.htmlandPortlet.titleproperties, respectively. -
The SuiteScript 1.0
setScript(scriptid)method is not available on the SuiteScript 2.1Portletobject. To associate a client script with a portlet, usePortlet.clientScriptFileIdorPortlet.clientScriptModulePath. These properties identify a script file or module path, not a script record ID.
Method arguments also change:
-
The SuiteScript 1.0
nlobjPortlet.addColumn(name, type, label, just)method takes individual arguments, while the SuiteScript 2.1Portlet.addColumn(options)method takes an options object. Thenameandjustarguments correspond tooptions.idandoptions.align, respectively. -
The SuiteScript 1.0
nlobjPortlet.addEditColumn(column, showView, showHrefCol)method takes annlobjColumnobject forcolumn. In SuiteScript 2.1,Portlet.addEditColumn(options)takes a column ID inoptions.columnand supports the additional optional propertiesoptions.link,options.linkParam, andoptions.linkParamName. -
The
nameargument of the SuiteScript 1.0nlobjPortlet.addField(name, type, label, source)method corresponds tooptions.idin the SuiteScript 2.1Portlet.addField(options)method. -
The
indentargument of the SuiteScript 1.0nlobjPortlet.addLine(text, url, indent)method corresponds tooptions.alignin the SuiteScript 2.1Portlet.addLine(options)method. Both specify an indent level from 0 to 5.
For more information about the portlet script type in SuiteScript 2.1, see SuiteScript 2.1 Portlet Script Type.
Suitelet Script Type Differences
A SuiteScript 1.0 Suitelet function receives separate request and response arguments. In SuiteScript 2.1, the onRequest entry point receives a context object with request and response properties. Suitelets run on the server in both versions.
In SuiteScript 1.0, call setScript(script) on the form, list, or assistant object and pass the client script's script ID. In SuiteScript 2.1, use the corresponding object's clientScriptFileId or clientScriptModulePath property to identify the client script file or module path.
For more information about the Suitelet script type in SuiteScript 2.1, see SuiteScript 2.1 Suitelet Script Type.
User Event Script Type Differences
User event functions have similar triggers in both versions, but receive event data differently:
-
SuiteScript 1.0 passes
typeandformas separate arguments to abeforeLoadfunction. SuiteScript 2.1 passes a context object withcontext.typeandcontext.formproperties. -
In
beforeLoad, the SuiteScript 1.0requestargument corresponds to SuiteScript 2.1context.request. This value is available for browser requests, but not when a server triggers the event. -
The SuiteScript 1.0
nlapiGetNewRecord()function corresponds tocontext.newRecordin the SuiteScript 2.1beforeLoad,beforeSubmit, andafterSubmitentry points. -
The SuiteScript 1.0
nlapiGetOldRecord()function is documented forbeforeLoad,beforeSubmit, andafterSubmit. In SuiteScript 2.1, thebeforeSubmitandafterSubmitcontext objects includecontext.oldRecord, but thebeforeLoadcontext object does not. -
SuiteScript 1.0 passes the event type as a
typeargument to each user event function. In SuiteScript 2.1,context.typeidentifies the event type. Compare it with values from thecontext.UserEventTypeenum when branching your script logic.
For more information about the user event script type in SuiteScript 2.1, see SuiteScript 2.1 User Event Script Type.
Workflow Action Script Type Differences
Here's how workflow action scripts differ between SuiteScript 1.0 and 2.1:
-
In SuiteScript 2.1, a workflow action script includes the
onActionentry point. There is no equivalent event type in SuiteScript 1.0. -
The
idargument in SuiteScript 1.0 corresponds to theworkflowIdproperty of the SuiteScript 2.1onActioncontext object. -
The SuiteScript 1.0
formargument corresponds toscriptContext.formin SuiteScript 2.1. The form is available only in thebeforeLoadcontext. -
The SuiteScript 1.0
typeargument corresponds toscriptContext.typein SuiteScript 2.1. -
The SuiteScript 2.1
onActioncontext object includes thenewRecordandoldRecordproperties.
For more information about the workflow action script type in SuiteScript 2.1, see SuiteScript 2.1 Workflow Action Script Type.