Skip to main content

NetSuite SuiteScript types with examples

Understanding NetSuite SuiteScript Types with Examples

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

Popular posts from this blog

Complete Guide to NetSuite AI Connector via Claude AI

NetSuite AI Connector to Claude AI - Complete Setup Guide Overview The NetSuite AI Connector Service enables direct integration between NetSuite and Claude AI, allowing you to access NetSuite data and functionality through natural language interactions with Claude. This integration leverages the Model Context Protocol (MCP) to provide secure, real-time access to your NetSuite environment. It's important to note that Claude is currently the only AI agent supported by NetSuite's AI Connector Service. Prerequisites NetSuite Requirements Active NetSuite account with Administrator privileges (for initial setup) NetSuite AI Connector Service enabled in your account Access to Setup > Integration > Manage Integrations Understanding of your NetSuite account structure and customizations Claude Requirements Claude Pro subscription Access to claude.ai Modern web browser (Chrome, Firefox, Safari, or Edge) Security Consideration...

Connecting to ADW in Oracle NetSuite Analytics Warehouse

Using Oracle Autonomous Data Warehouse with NetSuite Analytics Warehouse Introduction The wallet is a .zip file that contains credentials necessary to connect to the Oracle Autonomous Data Warehouse (ADW) instance associated with NetSuite Analytics Warehouse (NSAW). This blog post will guide you on how to use it effectively. Downloading the Wallet The wallet file is downloaded from the NSAW Console, under the Warehouse tile. The wallet.zip file will be downloaded to your local computer, ready for use. Connecting to ADW in Oracle SQL Developer The wallet file plays a crucial role in establishing a connection to the ADW instance in Oracle SQL Developer. Here are the steps: When creating a new connection in Oracle SQL Developer, set the connection type to "Cloud Wallet". Use the wallet.zip file as the Configuration File. The wallet file, along with the ADMIN user and the password set using Reset Credentials on the same screen in NSAW, are used t...

NetSuite Is Killing TBA in 2027 - Here's How to Prepare

NetSuite Is Killing TBA in 2027 — Here's How to Prepare In a significant move that will impact many businesses and their integrations, NetSuite has announced the phasing out of Token-Based Authentication (TBA) by 2027. This decision marks a pivotal change in how users will authenticate and connect to NetSuite's services. As businesses increasingly rely on seamless integration for operational efficiency, understanding the implications of this transition and preparing adequately is crucial. Here’s everything you need to know about this change and a step-by-step guide on how to prepare. What’s Actually Happening? NetSuite is moving away from Token-Based Authentication due to evolving security standards and technological advancements. From 2027 onwards, new TBA integrations will not be allowed, and the use of TBA with SOAP web services will be phased out entirely by 2028. This aligns with a broader industry trend towards more secure and efficient authentication methods. Why the...