In NetSuite, a script file and script record define the code and entry points, but the Script Deployment record controls where, when, and for whom the script runs.
For User Event and Client scripts, the deployment record’s Applies To field determines the record type that triggers the script, such as Sales Order, Invoice, Customer, Vendor Bill, or a custom record.
For example, a User Event script may already be deployed on Sales Order, but the same logic also needs to run on Invoice. Instead of changing the existing Sales Order deployment, create a new deployment record for the same script and set Applies To to Invoice. This keeps the script active on Sales Orders while adding a separate deployment for Invoices.
Sample Code (When a new record is being created, automatically default the Entity field to specific internal ID)
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/
define(['N/record'], function(record) {
function beforeLoad(context) {
// Run this logic only when a new record is being created
if (context.type === context.UserEventType.CREATE) {
var currentRecord = context.newRecord;
// Set the default value of the Entity field to internal ID 5381
currentRecord.setValue({
fieldId: 'entity',
value: 5381
});
}
}
return {
beforeLoad: beforeLoad
};
});
Note
Before creating the new deployment, confirm the following:
- The script file is already uploaded to the File Cabinet.
- The script record already exists.
To check, click Explore (hamburger icon in the bottom left corner beside the home button). In the menu, go to Customization > Scripting > Scripts.
- Your role has the required SuiteScript permissions.
- The target record type supports SuiteScript.
- The script logic is safe for the new record type. For example, a script written for Sales Orders may reference fields that do not exist on Invoices.
Deploy the Script to Another Record
1. Open the existing script record
To check, click Explore (hamburger icon in the bottom left corner beside the home button). In the menu, go to Customization > Scripting > Scripts.
Search for the existing script and open it in View or Edit mode.
2. Create a new deployment
Click Deploy Script
3. Set the target record
On the Script Deployment page, locate the Applies To field.
Select the new record type where the script should run.
4. Enter a deployment ID
In the ID field, enter a meaningful deployment ID.
Example: _ue_invoice_validation
5. Configure deployment status
Set the deployment status based on the testing stage.
- Testing while validating the script. This limits execution during testing.
- Use Released when the deployment is ready for production users.
6. Confirm the Deployed box
Make sure the Deployed box is checked.
7. Configure optional settings
Depending on the script type, review the following fields and subtabs:
SettingPurpose
Setting | Purpose |
|---|
Event Type | Limits the script to specific events, such as Create, Edit, View, or Delete. |
Log Level | Controls which log messages appear on the Execution Log. |
Execute as Role | Determines whether the script runs using a specific role. |
Audience | Controls which roles, employees, groups, departments, or subsidiaries are affected. |
Context Filtering | Limits execution by execution context or localization context. |
8. Save the deployment
Click Save.
The script is now deployed to the new record type.
The original deployment remains active on Sales Order, and the new deployment runs the same script on Invoice.
Disclaimer: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Oracle + NetSuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.
Oracle + NetSuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Oracle + NetSuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.
Oracle + NetSuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.
To learn more about NetSuite Next features, updates, and best practices, follow the NetSuite Next category.