N/util Module in SuiteScript: Type Verification Methods
The N/util module provides methods for verifying object and primitive types in SuiteScript, aiding effective script development.
The N/util module allows SuiteScript 2.x developers to access various methods designed to verify object and primitive types. These methods can also be accessed via the global util object, which facilitates type checking throughout your scripts. This capability is essential for ensuring data integrity and type correctness in your applications.
Available Methods
The following table outlines the N/util module methods, their return types, supported script types, and descriptions:
| Name | Return Type | Supported Script Types | Description |
|---|---|---|---|
util.each(iterable, callback) | Object or Array | Client and server scripts | Iterates over each member in an object or array. |
util.extend(receiver, contributor) | Object | Client and server scripts | Copies the properties in a source object to a destination object. |
util.isArray(obj) | boolean | Client and server scripts | Returns true if obj is a JavaScript Array object, otherwise false. |
util.isAsyncFunction(obj) | boolean | Client and server scripts | Returns true if obj is a JavaScript Async Function, otherwise false. |
util.isBoolean(obj) | boolean | Client and server scripts | Returns true if obj is a JavaScript Boolean, otherwise false. |
util.isDate(obj) | boolean | Client and server scripts | Returns true if obj is a JavaScript Date object, otherwise false. |
util.isFunction(obj) | boolean | Client and server scripts | Returns true if obj is a JavaScript Function or Async Function, otherwise false. |
util.isNumber(obj) | boolean | Client and server scripts | Returns true if obj is a JavaScript Number object or evaluates to a Number object, otherwise false. |
util.isObject(obj) | boolean | Client and server scripts | Returns true if obj is a plain JavaScript object, otherwise false. |
util.isRegExp(obj) | boolean | Client and server scripts | Returns true if obj is a JavaScript Regular Expression object, otherwise false. |
util.isString(obj) | boolean | Client and server scripts | Returns true if obj is a JavaScript String object, otherwise false. |
Practical Use Case
To illustrate how to utilize the N/util methods, consider the following example, which demonstrates how to use the util.each method to set fields on a sales order record:
1/**2 * @NApiVersion 2.x3 */4 5require(['N/record', 'N/util'], function(record, util){6 // Create a sales order7 var rec = record.create({8 type: 'salesorder', 9 isDynamic: true10 });11 rec.setValue({12 fieldId: 'entity',13 value: 10714 });15 16 // Set up an object containing an item’s internal ID and the corresponding quantity17 var itemList = {18 39: 5, 19 38: 120 }21 22 // Iterate through the object and set the key-value pairs on the record23 util.each(itemList, function(quantity, itemId){ // (5, 39) and (1, 38)24 rec.selectNewLine('item');25 rec.setCurrentSublistValue('item','item',itemId);26 rec.setCurrentSublistValue('item','quantity',quantity);27 rec.commitLine('item');28 });29 30 var id = rec.save();31});In this example, the script creates a sales order and sets item quantities dynamically using the util.each method to iterate over an itemList object.
Who This Affects
- Administrators: Manage script deployments and ensure correct usage of the N/util module in scripts.
- Developers: Implement the N/util module methods to enhance type verification in SuiteScript scripts.
Key Takeaways
- The N/util module is essential for type checking in SuiteScript 2.x.
- It enables effective iteration over objects and arrays with its
eachmethod. - Developers can utilize various utility methods to verify data types, promoting script reliability and correctness.
Frequently Asked Questions (4)
Can the type verification methods in the N/util module be used in both client and server scripts?
What does the util.isArray method return when checking if an object is a JavaScript Array?
How can I iterate over an object or array in SuiteScript using the N/util module?
Are the type verification methods in the N/util module supported in SuiteScript 1.0?
Was this article helpful?
More in SuiteScript
- SuiteScript 2.1 Enhancements in NetSuite February Updates
SuiteScript 2.1 now supports async features and PATCH method. Discover the latest API and SuiteProcurement improvements.
- Scheduling Map/Reduce Script Deployments in NetSuite
Learn to schedule map/reduce script submissions, including one-time and recurring options in NetSuite.
- Binary File Support in N/https Module for SuiteScript
SuiteScript enhances capabilities with binary file support in the N/https module, allowing improved data handling in external communications.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
