NetSuite Suite Script APIs support the creation of different standard record types, allowing for a wider customization. Included in the supported record types is also the Script Deployment record. This allows for deployments to be created programmatically when using Suite Script.
It can be helpful, for example, if one single script file needs to be deployed in different records or if the deployment is specific to that customization.
There are a few things to consider when creating a Script Deployment. For every deployment in NetSuite a Script records needs to exist already. Creating a new deployment in NetSuite without selecting a script first will result in the error “Record does not exist”. The same will happen in Suite Script.
The sample below shows how to pass the script ID in the object in order to create the deployment. Is important to note that the Script that will execute this code is already deployed in order to be executed. Using the N/record Module and a User Event Script.
- Navigate to Customization > Scripting > Scripts > New
- Upload the Script File with the sample code below.
- Click Create Script Record
- Basic Information:
- Name: Enter Script Name
- ID: Enter the Script ID
- Click Save & Deploy
- Basic Information:
- Applies To: Enter Sales Order
- ID: Enter Deployment ID
- Status: Select Released
- Log Level: Select Debug
- Click Save
/**
* @NApiVersion 2.0
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define(['N/record'],
/**
* @param {record} record
*/
function (record) {
/**
* Function definition to be triggered before record is loaded.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {Record} scriptContext.oldRecord - Old record
* @param {string} scriptContext.type - Trigger type
* @Since 2015.2
*/
function afterSubmit(scriptContext) {
var deployment = record.create({
type: record.Type.SCRIPT_DEPLOYMENT,
isDynamic: true,
defaultValues: {
script: '1306' // The Script Internal ID you are creating the deployment for;
}
});
log.debug({ title: 'Deployment Object', details: deployment });
}
return {
afterSubmit: afterSubmit
};
});