Setting Values with SuiteScript Current Record Module

SuiteScript's currentRecord module allows developers to set field values for records efficiently using various parameter types.

·2 min read·View Oracle Docs

TL;DR Opening

The currentRecord module in SuiteScript allows developers to set the value of specific fields on records easily. It supports various parameter types for different field types, streamlining record management in NetSuite.

Method Description

The setValue method within the currentRecord module is crucial for setting field values in records. This function supports numeric values, Date instances, conditional booleans, and other data types, thereby enabling efficient record manipulation, especially during client-side operations.

Supported Script Types

  • Client scripts

For more detailed script type information, refer to the SuiteScript 2.x Script Types.

Parameters

The options parameter is a JavaScript object containing the following properties:

ParameterTypeRequired / OptionalDescription
options.fieldIdstringrequiredThe internal ID of the field (standard or custom). For details, refer to Finding Internal IDs of Record Fields.
options.valuenumberDatestring
  • Text, Radio, Select, and Multi-Select fields take string values.
  • Checkbox fields require boolean values.
  • Date and DateTime fields utilize Date objects.
  • Integer, Float, Currency, and Percent fields take numeric values. | options.ignoreFieldChange | boolean | optional | If set to true, any field change and associated events are ignored. Defaults to false. | | options.forceSyncSourcing | boolean | optional | If set to true, dependent field information is sourced synchronously. This can help ensure that field sourcing completes before APIs are triggered, which can prevent improper results in some browsers. Defaults to false.

Errors

When using the setValue method, the following error codes may be encountered:

  • INVALID_FLD_VALUE: Thrown if the options.value does not match the required field type.
  • SSS_MISSING_REQD_ARGUMENT: Indicates that a required argument is not provided or undefined.

Syntax

Here’s a basic syntax illustration utilizing the setValue method. This is not a complete functional example; please refer to the relevant module scripts for full samples.

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

Related Topics


Who This Affects

This information is primarily useful for:

  • Developers
  • Client script authors
  • NetSuite administrators involved in record management

Key Takeaways

  • The setValue method allows effective management of field values through various data types.
  • Parameters must correspond correctly with expected field types to prevent errors.
  • Synchronous sourcing can alleviate timing issues in browsers, ensuring reliable data handling.

Frequently Asked Questions (4)

Can you use the currentRecord module's setValue method in server-side scripts?
No, the setValue method within the currentRecord module is only supported for client scripts.
What happens if you do not provide the required options.fieldId when using setValue?
If the required fieldId argument is not provided, the setValue method will throw an error: SSS_MISSING_REQD_ARGUMENT.
What data type should be used for Date fields when setting values using the setValue method?
When setting values for Date and DateTime fields using the setValue method, you should use Date objects.
Does the ignoreFieldChange parameter default to true in the setValue method?
No, the ignoreFieldChange parameter defaults to false, meaning field change events are triggered by default unless explicitly set to true.
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 SuiteScript

View all SuiteScript articles →