SuiteScript API
Use SuiteScript Functions and SuiteScript Standard Objects to extend the NetSuite application and create your
own custom forms, records, and business processes.
SuiteScript Functions
SuiteScript functions are divided into the following categories:
*
*
*
*
Core SuiteScript Functions
Core SuiteScript functions are available in both Client and Server SuiteScript contexts.
Initializes a new record using field data from an existing record and returns an nlobjRecord.
Instantiates an nlobjError object with a user-defined error code and description
Initializes a new record and returns an nlobjRecord containing all the default field data for that record type.
Deletes and commits new records or changes applied to an existing record and returns the internalId for the committed record.
nlobjContext object: returns context information (metadata) about current user and script execution
Use to branch scripts depending on the metadata. For example, you may want the script to perform in one way when a form is accessed via the UI and another when the form is accessed via Web services.
Returns the internalId for the current user’s department
fldnam: String - the name of the value whose field is being returned
Returns the value of a field on the current record
nlapiGetFieldValue is available only in Client and User Event SuiteScripts.
type: String - the name of the line item group
Returns the number of lines in a group for the current record
nlapiGetLineItemCount is available only in Client and User Event SuiteScripts.
type: String - the name of the line item group
fldnam: String - the name of the fields whose value is being returned
linenum: Integer - the line number for this field (1-based)
nlapiGetLineItemValue is available only in Client and User Event SuiteScripts.
Note: You cannot set default line item values when the line is not in edit mode.
Returns the internalId for the current user's location
Returns the internalId for the record whose form the user is currently on, or for the record that the current user event script is executing on.
Use to retrieve the internalId of the current record in a User Event script.
Note: This API is only available to Client and User Event SuiteScripts.
Returns the recordType for the record whose form the user is currently on, or for the record that the current User Event script is executing on.
Use to retrieve the record type of the current record in a User Event SuiteScript.
Note: This API is only available to Client and User Event SuiteScripts.
Returns the internalId for the current user's role
line: the line number in which to insert new line (only valid for User Event scripts)
Inserts a line above the currently selected line in a sublist
Note: This API is only available to Client and User Event scripts
Reads an existing record from the system and returns an nlobjRecord containing all the field data for that record.
type: sets the recordType to perform a field lookup on
fields: set an array of column/field names to look up, or a single column/field name
text: returns the display name for this field (valid only for SELECT fields)
Returns a single value (or text) or an associative Array of fieldname -> value (or text) pairs depending on the fields argument
Convenient helper function used to perform searches for field(s) on a records.
line: the line number in which to insert new line (only valid for User Event scripts)
Note: This API is only available to Client and User Event scripts
url: String (fully qualified unless NetSuite page)
postdata: postdata used for a POST request. It can either be an associative array of form parameters or a String. If null, then a GET request is used
headers: Custom HTTP headers to be included in the request
callback: a callback function called when request is completed (Client SuiteScript only)
target: target window where request should be made (Client SuiteScript only)
*
inline: synchronous AJAX call (default selection)
*
popup: navigate in new browser window
*
window: navigate in current browser window
response: nlobjResponse that contains the response
type: recordtype or tasklink intenalId
identifier: The primary id for this resource (recordType for RECORD)
id: the secondary id for this resource (recordId for RECORD)
editmode: for RECORD calls, this determines whether to return a URL for the record in EDIT mode or VIEW mode
Return the URL to an internal NetSuite resource
Note: Using a user-defined scriptId to reference custom records and lists, saved searches, and scripts is not currently supported.
filters: an array of nlobjSearchFilter objects or a single nlobjSearchFilter
columns: an array of nlobjSearchColumn objects or a single nlobjSearchColumn
nlobjSearchResult[] : An array of nlapiSearchResult objects
Performs a search using a set of criteria and columns or alternatively using an existing saved search.
author: the internalId of an employee record (this is the sender) Must be an employee record and defaults to script deployer ID)
recipient: recipient internalID or external email address
body: body of the outgoing email. Note: The body argument is required. A JavaScript exception will be thrown if the body of the email message is left blank.
cc[ ] : an array of email addresses or a single email address to copy
bcc[ ]: array of email addresses or a single email address to blind copy
records: An associative array of internal records to associate this email with. The following options are valid:
*
transaction - Transaction/Opportunity
*
record - Custom record internalId
*
recordtype - Custom recordType internalId
Note: You can use NetSuite email templates to construct the body of the email using nlapiMergeEmail, which performs a merge operation using a NetSuite email template and up to two business records.
fldnm: String - the name of the field being set
value: String - the value the field is being set to
firefieldchanged: Boolen - if true then the fieldchange script for that field is executed. (Only available in Client SuiteScript)
This API can be used during beforeLoad scripts to initialize field scripts on new records or non-stored fields.
nlapiSetFieldValue is available only in Client and User Event SuiteScripts.
type: String - the name of the line item group
fldnam: String - the name of the field being set
linenum: Integer - the line number for this field (1-based)
value: String - the value the field is being set to
nlapiSetLineItemValue can be used during beforeLoad scripts to initialize line items on new records.
nlapiSetLineItemValue is available only in Client and User Event SuiteScripts.
identifier: The primary id for this resource (recordType for RECORD)
id: The secondary id for this resource (recordId for RECORD,)
editmode: if TRUE, returns the URL to an existing record in EDIT mode
parameters: An associative array of additional URL parameters - (All parameters must be prefixed with custparam)
Sets the redirect URL or redirects user directly (for user event load script). You can only redirect to pages within NetSuite.
Note: All parameters must be prefixed with custparam otherwise an SSS_INVALID_ARG error will be thrown.
Note: Using a user-defined scriptId to reference custom records and lists, saved searches, and scripts is not currently supported.
doSourcing: if TRUE, enables automatic field sourcing
Submits and commits new records or changes applied to an existing record and returns the internalId for the committed record.
type: the record type for the existing record
transformType: the record type you are transforming the existing record into
transformValues: an array of fieldname-> value pairs containing field defaults used for transformation
Initializes a new record using data from an existing record of a different type and returns an nlobjRecord.
Client SuiteScript Functions
Client functions are only available in Client SuiteScript contexts.
 
type: String - the name of the line item group
Cancels any uncommited changes to the current line of a sublist
type: String - the name of the line item group
Saves/commits the changes to the current line in a line item group on a sublist.
This is the equivalent of clicking Done for a line item in the UI.
fldnam: String - the name of the field to enable/disable
val: Boolean - if ‘T’ then the field is disabled, otherwise it is enabled
Sets the given field to disabled or enabled based on the value (true or false).
type: String - the name of the line item group
fldnam: String - the name of the field to enable/disable
val: Boolen - if ‘T’ then the field is disabled, otherwise it is enabled
Sets the given line item field of the given type to disabled or enabled based on the value (true or false).
type: String - the name of the line item group
Returns the line number of the currently selected line in a group
type: String - the name of the line item group
fldnam: String - the name of the field being set
linenum - the line number for this field (sublists only)
Returns the display name of a select field (based on its current selection) on the currently selected line
Gets the text value of the given line-item selection field in the form before it has been added. Typically used in validate line functions.
type: String - the name of the line item group
fldnam: String - the name of the field being set
linenum - the line number for this field (sublists only)
Returns the value of a field on the currently selected line
Retrieves the value of the given line-item field before it has been added to the form. Typically used in validate line functions.
fldnam: String - the name of the field being set
Returns the display name for a select field corresponding to the current selection
Important: nlapiGetFieldText can NOT be used on hidden fields.
type: String - the name of the line item group
fldnam: String - the name of the field being set
linenum: Integer - the line number for this field (1-based)
Returns the display name of a select field (based on it's current selection) in a line item group
Gets the text value of the given selection field on the line item at the given index.
value: the value of the select option (should be unique)
selected: True if this option should become the default option
Adds a select option to a select/multiselect field added via script
type: String - the name of the line item group
Returns true if the currently selected line of the sublist has been edited
Determines whether any changes have been made to a line item group
type: String - the name of the line item group
Redraws a line item group to reflect recent changes to the underlying data
value: the value of the select option to be removed or null to delete all the options
Removes a single select option from a select or multiselect field added via script
type: String - the name of the line item group
type: String - the name of the line item group
fldnam: String - the name of the field being set
text: String - the display name associated with the value that the field is being set to
firefieldchanged: if true, then field changed scripts for that field are executed
Sets the value of a select field on the currently selected line using the display name
type: String - the name of the line item group
fldnam: String - the name of the field being set
value: String - the value the field is being set to
firefieldchanged: Boolean - if true then fieldchanged scripts for that field are executed
Sets the value of the given line-item field before it has been added to the form. Typically used in validate line functions.
fldname: String - the name of the field being set
txt: String - the display name associated with the value that the field is being set to
firefieldchanged: Boolean - if true, then fieldchanged scripts for that field are executed
Sets the value of a select field on the current record using the display name
Server SuiteScript Functions
Server SuiteScript functions are only available in Server SuiteScript contexts.
Returns an nlobjRecord containing all the values being used for a write operation
Available in beforeSubmit and afterSubmit SuiteScript User Event scripts only.
Returns an nlobjRecord containing all the values for the current record prior to the write operation
Available in beforeSubmit and afterSubmit SuiteScript User Event scripts only.
type: log type ( audit, debug, error, emergency)
title: a title used to organize log entries (max length: 99 characters)
details: details of the log entry (max length: 3000 characters)
Logs a message, audit, or note against a SuiteScript script deployment.
baseType: The recordType for the primary record used in the merge
baseId: The internalId for the primary record used in the merge
altType: The recordType for the secondary record used in the merge
altId: The internalId for the secondary record used in the merge
Returns a String containing the results
Note: With nlapiSendEmail you can use NetSuite email templates to construct the body of the email using nlapiMergeEmail.
nlapiMergeEmail performs a merge operation using a NetSuite email template and up to two business records.
deployment: the deployment internalId
parameters: optional third argument. An associative array of parameter values used to override the script parameter values for this execution
Returns a String whose value is QUEUED if the script was successfully queued by this call, or it returns the script's current status or null (if the script is undeployed or invalid)
*
INQUEUE: the scheduled script is in queue waiting to be run
*
INPROGRESS: the scheduled script is currently running
*
ABORTED: the scheduled script did not finish running. Scripts are aborted if they are scheduled to run during regular NetSuite maintenance periods.
*
FAILED: the scheduled script failed due to incorrect coding. The developer should review the script to ensure there were no errors in the code.
Schedules a long-running script for immediate execution if its current status is Scheduled or Not Scheduled.
*
nlapiScheduleScript can only be called once per script
*
nlapiScheduleScript can only be called by User Event scripts.
Library SuiteScript Functions
Library functions are SuiteScript utility functions that are available in all SuiteScript contexts.
You can use these functions when writing User Event, Scheduled, and Portlet scripts.
days: Integer - number of days being added to the date
days: Integer - number of months being added to the date
Adds/subtracts a number of months to or from a Date object
d: Date object being converted into a String
Converts a Date object into a String using the current user's date format
Encrypts a String using an asymmetrical 128-bit encryption algorithm (same algorithm used to store password fields)
Prepares a String for use in XML by escaping XML markup (angle brackets, quotes)
xpath: XPath expression used to query node
Selects a node from an XML document using an XPath expression
xpath: XPath expression used to query node
Selects an array of nodes from an XML document using an XPath expression
xpath: XPath expression used to query node
Selects a value from an XML document using an XPath expression
Selects an array of values from an XML document using an XPath expression
Converts a String to a Date object using the current user's date format
Document: org.w3c.dom.Document
Converts (serializes) an XML document into a String
SuiteScript Standard Objects
Note: The only constructable objects are nlobjSearchColumn and nlobjSearchFilter.
Encapsulates user information and execution context
user entity internalID
user role internalID
user company internalID
user email address
execution context: user interface, web services, offlineclient, smbxml
Returns the remaining number of units for the current script
*
SCRIPT script parameter (defined per script)
*
SESSION session variable (volatile setting defined per session)
*
PREFERENCE company or user preference
name: the name of the script/system setting
Returns a system or script setting. (Only available in Server SuiteScript.)
*
SESSION session variable (volatile setting defined per session)
name: the name of the script/system setting
value: the new value for the script/system setting
Returns a system or script setting. (Only available in Server SuiteScript.)
Primary object used to encapsulate errors in the system
Returns the error code (user-defined or system) associated with this error
Returns the error message (user-defined or system) associated with this error
Returns the stack trace associated with this error
Returns the internalId of the submitted record if this error was thrown in an after-submit script
Returns the name of the User Event script (if applicable) that the error was thrown from
Primary object used to encapsulate records in the system
Returns the record type
Returns the record intrenalId
name: the name of the field being set
value: the value of the field being set to (String)
name: the name of the field being set
values: the value the field is being set to (Array)
Returns an array of field values (only applicable for multiselects)
Sets the value of a multiselect field
name: the value the field is being set to (Array)
name: the name of the multi-select field whose value is being returned
Returns an array of field values (only applicable for multiselects)
setLineItemValue( group, name, linenum, value )
name: the name of the field being set
linenum: the line number for this field (1-based)
The group argument refers to the type of sublist being referenced. For a list of field name values for each group argument, refer to the SuiteScript Reference Guide.
name: the name of the field whose value is being returned
linenum: the line number for this field (1-based)
Returns the value of a line item field
The group argument refers to the type of sublist being referenced. For a list of field name values for each group argument, refer to Server SuiteScript Reference Guide.
Returns the number of lines in a machine
The group argument refers to the type of sublist being referenced.
The first line number on a machine is 1 (NOT 0).
Returns an associative array of all the changed fields in this record and their values
This method does not return ALL fields on a record. This method returns only the fields that have been changed.
linenum: the line number for this field (1-based)
linenum: the line number for this field (1-based)
Removes an existing new line from a line item group
Primary object used to encapsulate an HTTP GET or POST request
Return an array of all the header names in the request
Return an array of all the parameter field names in the request
Return the body of the request as a String
Return the value of a header in the request
Return the number of lines in a line item group
name: the name of the field whose value is returned
Return the value of a line item
Return the request type
name: the name of the request parameter whose value is returned
Return the request parameter value for a parameter
name: the name of the request parameter whose value is returned
Return the request parameter values as an Array for a parameter
Return the full URL of the request
Primary object used to encapsulate a server response
Return an Array containing all the headers returned by the server
Only available in return value of call to nlapiRequestURL
Return the body returned by the server
Only available in return value of call to nlapiRequestURL
Return the HTTP response code returned by the server
Only available in return value of call to nlapiRequestURL
Return the nlobjError thrown during request
Only available in return value of call to nlapiRequestURL in Client Public.SuiteScript
Return the value for a header returned by the server
Only available in return value of call to nlapiRequestURL
Sets the value of a response header.
Note: All user-defined headers must be prefixed with "Custom-Header" otherwise an SSS_INVALID_ARG error will be thrown.
setRedirectURL( type, identifier, ID, editmode, parameters)

identifier: the primary id for this resource (recordType for RECORD)
ID: the secondary id for this resource (recordId for RECORD,)
editmode: for RECORD calls, this determines whether to return a URL for the record in EDIT mode vs. VIEW mode
parameters: an associative array of additional URL parameters - (All parameters must be prefixed with custparam)
Note: All parameters must be prefixed with custparam otherwise an SSS_INVALID_ARG error will be thrown.
Note: Using a user-defined scriptId to reference custom records and lists, saved searches, and scripts is not currently supported.
output: String or Document being written
Writes a String or Document to the response output
object: standalone page object: nlobjForm or nlobjList
Generates a page using a page element object (nlobjForm or nlobjList)
Primary object used to encapsulate search return columns
join: the join id for this search return column
Constructor used to create a search return column
Returns the name for this search column
Returns the join id for this search column
Returns the summary type for this search column
Primary object used to encapsulate search filters
constructor( name, join, operator, value1, value2 )
name: the search filter name for this recordType
operator: (See the SuiteScript Reference Guide for a list of possible operators.)
value1: a filter value -or- special date field value -or- Array of values for select/multiselect fields - (The value1 argument is optional, depending on which operator was used.)
value2: a secondary filter value -or- special date field value for between/within style operators * lastbusinessweek - (The value2 argument is optional, depending on which operator was used. See the SuiteScript Reference Guide for a list of possible operators. )
When searching on checkbox fields, use the is operator with a T or F value to search for checked or unchecked fields, respectively.
Returns the name for this search filter
Returns the join id for this search filter
Returns the operator for this search filter
Primary object used to encapsulate a search result row
summary: the summary type used for this search column:
*
*
*
*
Returns the display name for this column (valid for non-stored select fields only)
This is only valid for non-stored fields of type SELECT
summary. the summary type used for this search column:
*
*
*
*
Returns the value for this column