setValue Method for SuiteScript CurrentRecord Object
The setValue method allows you to set field values on the current record in SuiteScript, essential for dynamic data handling.
The setValue method is a crucial part of the SuiteScript currentRecord module, enabling developers to programmatically set values for various record fields. This capability is particularly useful for client scripts where dynamic user inputs are required.
Method Description
The setValue method sets the value of a specified field on the current record. This method allows for various types of fields, including numeric, string, date, and boolean types.
Returns
The method returns the currentRecord.CurrentRecord object, allowing further manipulation of the record.
Supported Script Types
This method is applicable in Client scripts. For details on supported script types, refer to the SuiteScript 2.x Script Types.
Governance
There are no specific governance limits for this method.
Parameters
The setValue method accepts an object as its parameter. Each property of this object has specific requirements:
| Parameter | Type | Required / Optional | Description |
|---|---|---|---|
options.fieldId | string | required | The internal ID of a standard or custom body field. For more details, see Finding Internal IDs of Record Fields. |
options.value | number, Date, string, array, boolean | required | The value you want to set. This value must match the type of the field being set. For instance, string values for text fields, and boolean for checkboxes. |
options.ignoreFieldChange | boolean | optional | If set to true, it ignores any field change events that would typically follow. By default, this is set to false. |
options.forceSyncSourcing | boolean | optional | When set to true, it forces synchronous sourcing of dependent fields. This can help mitigate timing issues in certain browsers when handling events. Defaults to false. |
Errors
The setValue method may throw the following errors:
INVALID_FLD_VALUE: Triggered when theoptions.valuetype does not correspond with the targeted field type.SSS_MISSING_REQD_ARGUMENT: Triggered if any required arguments are either missing or undefined.
Syntax
Here’s a basic syntax example demonstrating the setValue method:
1//Add additional code 2...3objRecord.setValue({4 fieldId: 'item',5 value: true,6 ignoreFieldChange: true,7 forceSyncSourcing: true8});9...10//Add additional codeConclusion
Understanding how to utilize the setValue method effectively allows for more dynamic and interactive forms within NetSuite's scripting environment. Ensure to review the types of values that can be set based on field type to avoid errors during implementation.
Frequently Asked Questions (4)
Is the setValue method available in all NetSuite script types?
What happens if I provide a value that does not match the field type when using setValue?
Do I need to be concerned about governance limits when using the setValue method?
Can I prevent field change events when using 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