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
- Common SuiteScript Errors and Solutions for NetSuite
Common NetSuite script errors include INVALID_SCRIPT_DEPLOYMENT_ID and SSS_AUTHORIZATION_HEADER_NOT_ALLOWED. Learn effective solutions.
- Set Sublist Field Values in SuiteScript 2.x for Record Management
Set sublist field values in SuiteScript 2.x for effective record management using standard and dynamic modes.
- Setting Field Values in SuiteScript for Effective Record
Learn to set field values in SuiteScript effectively, troubleshooting common errors and understanding data types.
- SuiteScript 2.1 Enhancements and API Updates in NetSuite
SuiteScript 2.1 enables execution of 2.0 scripts and supports PATCH method for enhanced API capabilities.
Advertising
Reach SuiteScript Professionals
Put your product in front of NetSuite experts who work with SuiteScript every day.
Sponsor This Category