Setting Values with SuiteScript Current Record Module
SuiteScript's currentRecord module allows developers to set field values for records efficiently using various parameter types.
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:
| Parameter | Type | Required / Optional | Description |
|---|---|---|---|
options.fieldId | string | required | The internal ID of the field (standard or custom). For details, refer to Finding Internal IDs of Record Fields. |
options.value | number | Date | string |
- 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 totrue, any field change and associated events are ignored. Defaults tofalse. | |options.forceSyncSourcing| boolean | optional | If set totrue, 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 tofalse.
Errors
When using the setValue method, the following error codes may be encountered:
INVALID_FLD_VALUE: Thrown if theoptions.valuedoes 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.
1//Add additional code 2...3objRecord.setValue({4 fieldId: 'item',5 value: true,6 ignoreFieldChange: true,7 forceSyncSourcing: true8});9...10//Add additional codeRelated Topics
- currentRecord.CurrentRecord
- N/currentRecord Module
- SuiteScript 2.x Modules
- SuiteScript 2.x
Who This Affects
This information is primarily useful for:
- Developers
- Client script authors
- NetSuite administrators involved in record management
Key Takeaways
- The
setValuemethod 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?
What happens if you do not provide the required options.fieldId when using setValue?
What data type should be used for Date fields when setting values using the setValue method?
Does the ignoreFieldChange parameter default to true in the setValue method?
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