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.

·3 min read·View Oracle Docs

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:

ParameterTypeRequired / OptionalDescription
options.fieldIdstringRequiredThe internal ID of a standard or custom body field. Refer to Finding Internal IDs of Record Fields for more guidance.
options.valuenumber, Date, string, array, booleanRequiredThe 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.ignoreFieldChangebooleanOptionalIf 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 of options.value does 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:

suitescript
1// Example of setting a boolean value
2objRecord.setValue({
3 fieldId: 'item',
4 value: true,
5 ignoreFieldChange: true
6});

Alternatively, for Inline HTML fields:

suitescript
... // Assuming objRecord refers to your record object
objRecord.setValue(inlineHtmlFieldId, '<i>foo</i>'); // Returns text in cursive.
objRecord.getValue(inlineHtmlFieldId); // Returns '<i>foo</i>'
objRecord.getText(inlineHtmlFieldId); // Returns 'foo'

Related Topics

  • record.Record
  • N/record Module
  • SuiteScript 2.x Modules
  • SuiteScript 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.

Source: This article is based on Oracle's official NetSuite documentation.

Key Takeaways

  • The setValue method is essential for assigning field values in SuiteScript 2.x.
  • Parameter types must match the expected field types to avoid errors.
  • Use of ignoreFieldChange allows 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?
Yes, for fields that require specific formats like rate fields, you should use the Record.setText(options) method to ensure the value is in the correct string representation, such as including a percentage symbol (%).
What are the implications of setting 'ignoreFieldChange' to true in 'setValue' method?
Setting 'ignoreFieldChange' to true will bypass any field change events, which means that any associated scripts or workflows triggered by field changes will not be executed. This is useful when you want to update a field without triggering any additional automation.
What data types can be used with the 'options.value' parameter in 'setValue'?
The 'options.value' parameter can accept various data types including number, Date, string, array, and boolean, depending on the field's data type. Make sure to match the value type with the field type to avoid errors like 'INVALID_FLD_VALUE'.
How does the 'setValue' method handle errors if the value type doesn't match the field type?
If the 'options.value' type doesn't match the field type, the 'setValue' method will throw an 'INVALID_FLD_VALUE' error. It’s important to ensure that the data type of the value aligns with the expected type for the field.
Source: Parameters Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in General

View all General articles →