Introduction
NetSuite SuiteScript is a JavaScript-based API that allows developers to automate standard NetSuite tasks. SuiteScript is categorised into different types based on their functionality and usage. In this blog post, we will explore the different types of SuiteScript, and provide an example for each one.
SuiteScript 1.0 and SuiteScript 2.0
Before we delve into the different types of SuiteScript, it's important to note the two major versions: SuiteScript 1.0 and SuiteScript 2.0. SuiteScript 1.0 is the original version, while SuiteScript 2.0 is an updated version that offers a more modular, structured approach to scripting.
User Event Script
A User Event Script triggers when users perform certain actions on records, such as create, edit, delete, or view. It allows developers to customize workflows and business processes.
Example of User Event Script:
function beforeSubmit(type){
if (type == 'create'){
var record = nlapiGetNewRecord();
record.setFieldValue('custrecord_custom_field', 'Custom Value');
}
}
Client Script
Client Scripts run on the user's browser, not on the server. They are used to manage events that happen on the client side, such as field changes, form loads, or line item insertions.
Example of Client Script:
function fieldChanged(type, name){
if (name == 'custrecord_custom_field'){
alert('The custom field has been changed!');
}
}
Scheduled Script
Scheduled Scripts are designed to perform lengthy read-write operations on large numbers of records. They are particularly useful for tasks that may exceed the maximum execution time if run as a single operation.
Example of Scheduled Script:
function scheduledScript(){
var searchResults = nlapiSearchRecord('transaction', null, null, null);
for (var i = 0; i < searchResults.length; i++){
var record = nlapiLoadRecord(searchResults[i].getRecordType(), searchResults[i].getId());
record.setFieldValue('custbody_custom_field', 'Custom Value');
nlapiSubmitRecord(record);
}
}
Portlet Script
Portlet Scripts are used to create custom dashboard portlets. They allow developers to build interactive mini-applications that users can add to their dashboard.
Example of Portlet Script:
function portletScript(portlet, column){
portlet.setTitle('Custom Portlet');
var content = 'Welcome to the custom portlet!';
portlet.setHtml(content);
}
Wrap Up
NetSuite SuiteScript offers a wide variety of script types to cater to different needs and use cases. By understanding each type and its usage, developers can leverage SuiteScript to its full potential, thus enhancing the overall NetSuite experience.
Comments
Post a Comment