SuiteScript 2.0 Modules on the Client-Side Developer Console

Published March 19, 2023

For this article, I will show you how to leverage the SuiteScript 2.0 Modules available for Client-Side scripting. Many Developers and Admins may know how to leverage SuiteScript 1.0 APIs from the browser's developer Console (nlapiLoadRecord()), but did you know that you can require() and initialize SS2.0 Modules as well?
With a quick word of caution, leveraging Client-Side scripting is compelling, but always know that what you do affects the account you logged into. For example, if you load a record, make a change, and save the record on the Client-Side, it will change that record as if done on the Server-Side.

Require the Module

The first step to leveraging SS2.0 in the Dev Console is to require() in the module you want to use. Let's start with an easy Module that will not impact live data, the N/search module.
Open the Browser's Developer Console. I am using Chrome for this article. Hitting F12 will bring up the console. First, make sure you're in the Console section. Then type in require(['N/search']); and hit enter; this will load in the search Module.

Initialize a search Object

Now you will want to initialize a search Object by calling the module by typing the following into the console var search = require('N/search');. The search Object will now have all the methods and enumerations you are used to when writing Server-Side scripts.

Using the search Object

Let's try out one of my favorite methods, search.lookupFields(). I already know the internal id of the customer I want to look up the email for. In the console, you can now type the below method to return the email address for the customer's internal id 6.

search.lookupFields({
    type: search.Type.CUSTOMER,
    id: 6,
    columns: [
        'email'
        ]
});


This method returns an Object with the customer's primary email address.

{
    "email": "testcustomer@test.co"
}

Bonus Round

Now that we have the basic concept of leveraging SS2.0 on the Client-Side let's show off a fun use case. Sometimes I want to be lazy and update something on a record I am looking at quickly. Say the email address. Is it faster to click edit, wait for the record to load, wait for the caret to auto-enter the default text field (usually customer name), find the email field, enter the new email, and click Save, or leverage my favorite method on the N/record module, record.submitFields()?
Let's load in the record module and initialize a record Object. require(['N/record']); and then var record = require('record');. Here is a fun shortcut, SS1.0 API is always available in the console, meaning you can mix and match SS2.0 with SS1.0. Suppose you are already on the record page of the customer you want to update the email for, in our case, internal id 6. In that case, you can leverage nlapiGetRecordType() to get the current record type and nlapiGetRecordId() to get the current record id!

record.submitFields({
    type: nlapiGetRecordType(),
    id: nlapiGetRecordId(),
    values: {
        email: 'testap@test.co'
    }
});


This method returns the internal id of the record updated, 6 in our test here.

Summary

Client-Side SuiteScript 2.0 modules are great for debugging, testing how a specific method will work, or a quick and dirty fix to a record. One note is that using the browser's developer console will not work on any modules not exposed to the Client-Side. See N/task as an example of a Server-Side only module. Finally, this power is available to any user with permission. Leveraging the developer console can technically be done by any user. Client-Side modules are not restricted to the Admin or Developer type roles. If the user has permission to edit a record and can leverage the developer console, they can use the same methods discussed in this article.