Field Value Setting in SuiteScript 2.0 with N/record Module

Learn to set field values using the N/record module in SuiteScript 2.0. Understand data types and field order importance.

·3 min read·View Oracle Docs

Setting field values is crucial for effective record management in SuiteScript 2.0, utilizing the N/record module. This article explains how to correctly set values for different field types, ensuring accurate data entry and manipulation.

What is Setting Field Values?

Setting the value of a field is a foundational operation in SuiteScript 2.0. This can be done in both dynamic and standard modes. Understanding these modes is crucial as they influence how field values are handled during scripting operations.

Dynamic vs Standard Mode

  • Standard Mode: Field values are processed in an abstract manner and validated upon saving the record. There’s no need to set fields in a specific order.
  • Dynamic Mode: This mode behaves like the NetSuite UI, requiring careful attention to the order of field settings. Setting fields incorrectly could lead to overridden values, impacting the script’s behavior.

Method Description

The primary method of setting a field value is via the setValue(options) function in the N/record module. This method takes an options object, allowing for flexibility in what is set.

Parameters for setValue(options)

ParameterTypeRequired/OptionalDescription
options.fieldIdstringRequiredThe internal ID of the field you want to set.
options.valuenumberDatestring
options.ignoreFieldChangebooleanOptionalIf true, ignores the field change and secondary event triggered by it. Default is false.

Supported Value Types

  • Text and Radio fields accept string values.
  • Select fields can accept both string and number values.
  • Multi-Select fields require an array of values.
  • Checkbox fields accept boolean values.
  • Date fields should be assigned Date values.
  • Numeric fields (Integer, Float, Currency, Percent) accept number.
  • Inline HTML field values must be provided as strings, which are processed as HTML entities.

Error Handling

When setting values, it’s important to be aware of potential errors that may arise.

  • INVALID_FLD_VALUE: This error indicates a mismatch between the type of the value being set and the field type.
  • SSS_MISSING_REQD_ARGUMENT: This error occurs when a required parameter is missing or undefined.

Code Samples

The following code demonstrates how to use setValue() to set a field and what to expect when working with INLINEHTML fields.

Standard Setting Value Example

suitescript
1// Add additional code
2...
3objRecord.setValue({
4 fieldId: 'item',
5 value: true,
6 ignoreFieldChange: true
7});
8...
9// Add additional code

Inline HTML Field Example

suitescript
...
objRecord.setValue(inlineHtmlFieldId, '<i>foo</i>'); // Returns text in cursive.
objRecord.getValue(inlineHtmlFieldId); // Returns '<i>foo</i>'
objRecord.getText(inlineHtmlFieldId); // Returns 'foo'
...

This foundational knowledge is essential for successful scripting in NetSuite, ensuring that field values are handled correctly as business processes demand.


Who This Affects

  • Developers working with SuiteScript 2.0
  • Administrators managing or customizing NetSuite records
  • Technical Users involved in integrations and custom applications

Key Takeaways

  • Setting field values correctly is essential for data accuracy.
  • Distinguish between dynamic and standard script modes to prevent value overrides.
  • Understand the specific value types required for different field types.
  • Implement error handling for robust scripts.

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

Frequently Asked Questions (4)

How does dynamic mode differ from standard mode when setting field values?
In dynamic mode, field values must be set in the correct order as it emulates the NetSuite UI, unlike standard mode where fields can be set in any order and are validated upon record saving.
What types of values can be assigned to different fields using setValue()?
Text and radio fields accept strings, select fields accept strings and numbers, multi-select fields require an array, checkbox fields accept boolean values, date fields require Date values, and numeric fields accept numbers. Inline HTML requires string values to be processed as HTML entities.
What are common errors encountered when setting field values?
Common errors include INVALID_FLD_VALUE, indicating a mismatch between the value type and field type, and SSS_MISSING_REQD_ARGUMENT, which occurs when a required parameter is missing or undefined.
Is it possible to ignore field change events when setting field values in SuiteScript 2.0?
Yes, by setting the ignoreFieldChange option to true in the setValue() function, you can ignore the field change and any secondary events triggered by it, although the default is false.
Source: Syntax 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 SuiteScript

View all SuiteScript articles →