Setting Field Values in SuiteScript 2.x for NetSuite
Learn to set field values in SuiteScript 2.x using the setValue method effectively for various field types.
The setValue method in SuiteScript 2.x allows developers to set the value of a field dynamically, which is crucial for effective record management within NetSuite. This method can be utilized in both client and server scripts, making it highly versatile.
Method Description
The setValue method assigns a value to a specified field on a record. Depending on whether you are in dynamic or standard mode, the way you handle these fields might change. In dynamic mode, field changes occur in real time, while in standard mode, they are processed in a deferred manner until the record is saved.
Important Note
For fields requiring specific formats, such as rate fields, use the Record.setText(options) method to ensure the appropriate string representation with a percentage symbol (%).
Parameters
The setValue method requires an options parameter, which is a JavaScript object. Below is a detailed table of the parameters you can use:
| Parameter | Type | Required / Optional | Description |
|---|---|---|---|
options.fieldId | string | Required | The internal ID of a standard or custom body field. Refer to Finding Internal IDs of Record Fields for more guidance. |
options.value | number, Date, string, array, boolean | Required | The value to set on the field, tailored to the field's data type. Text fields accept strings; Select fields accept strings or numbers; Multi-Select fields require an array; Checkbox fields require boolean values, etc. For Inline HTML fields, ensure the string is properly formatted as HTML entities. |
options.ignoreFieldChange | boolean | Optional | If set to true, this flag ignores field change events, defaulting to false to allow field changes to be processed. |
Error Handling
When utilizing the setValue method, you may encounter specific errors:
INVALID_FLD_VALUE: This error denotes that the type ofoptions.valuedoes not match the field type.SSS_MISSING_REQD_ARGUMENT: Thrown when a required argument is missing or left as undefined.
Syntax Example
The following code snippets illustrate how to use the setValue method:
1// Example of setting a boolean value2objRecord.setValue({3 fieldId: 'item',4 value: true,5 ignoreFieldChange: true6});Alternatively, for Inline HTML fields:
... // Assuming objRecord refers to your record objectobjRecord.setValue(inlineHtmlFieldId, '<i>foo</i>'); // Returns text in cursive.objRecord.getValue(inlineHtmlFieldId); // Returns '<i>foo</i>'objRecord.getText(inlineHtmlFieldId); // Returns 'foo'Related Topics
record.RecordN/record ModuleSuiteScript 2.x ModulesSuiteScript 2.x
Understanding the setValue method is essential for any developer working with records in SuiteScript 2.x, as it forms the backbone of how data is manipulated within NetSuite.
Key Takeaways
- The
setValuemethod is essential for assigning field values in SuiteScript 2.x. - Parameter types must match the expected field types to avoid errors.
- Use of
ignoreFieldChangeallows skipping events on updates. - Be aware of the differences between dynamic and standard mode when manipulating records.
Frequently Asked Questions (4)
Do I need to use the 'setText' method for rate fields in SuiteScript 2.x?
What are the implications of setting 'ignoreFieldChange' to true in 'setValue' method?
What data types can be used with the 'options.value' parameter in 'setValue'?
How does the 'setValue' method handle errors if the value type doesn't match the field type?
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.
