Field Object Syntax in SuiteScript for Custom Forms
Learn the syntax for adding field objects in SuiteScript, including parameters, methods, and best practices for custom forms.
The syntax for creating field objects in SuiteScript is essential for customizing forms and user interfaces in NetSuite environments. Understanding how to define field parameters and utilize available methods can significantly enhance user experience and data collection.
What is a Field Object?
A Field object is used to record or display information specific to your needs within forms created by SuiteScript. You can add these fields to various script types, including Suitelets and user event scripts, specifically at the beforeLoad entry point.
How to Add a Field Object
To add a Field object, you will typically use one of the following methods:
Assistant.addField(options)Form.addField(options)Sublist.addField(options)
These methods allow you to define essential attributes, such as the field's internal ID, label, and type.
Supported Script Types
The following script types support the addition of Field objects:
- Suitelets
- User Event Scripts (at the beforeLoad entry point)
Field Object Parameters
When using the options parameter to define the field, you must provide the following:
| Parameter | Type | Required/Optional | Description |
|---|---|---|---|
options.id | string | Required | The internal ID for this field. Must be in lowercase and follow the appropriate naming structure (e.g., custpage_example). |
options.label | string | Required | The display label for the field that users will see. |
options.type | string | Required | The field type, defined by the serverWidget.FieldType enum (e.g., TEXT, SELECT). |
options.source | string | Optional | The internalId or scriptId of the source list if using a select or multi-select field. If adding custom options, set this to NULL. |
Important Considerations
- Field types like long text have specific character limits. For fields created with SuiteScript, the limit is 100,000 characters. Fields created via SuiteBuilder can have up to 1,000,000 characters.
- Custom options for select fields should be added after setting the
sourceparameter to NULL, and then using theField.addSelectOption(options)method to define these options.
Code Sample
Here is an example illustrating the syntax for adding a field to a form:
1//Add additional code 2...3var form = serverWidget.createForm({4 title : 'Simple Form'5});6var field = form.addField({7 id : 'custpage_text',8 type : serverWidget.FieldType.TEXT,9 label : 'Text'10});11...12//Add additional codeThis snippet demonstrates creating a simple form and adding a text field to it. You can expand upon this foundation with further validation or additional fields based on your needs.
Key Takeaways
- Field objects are essential for collecting specific information in custom forms.
- Ensure the correct parameters are defined to avoid errors during script execution.
- Use SuiteScript's defined field types to maximize functionality and user experience.
Frequently Asked Questions (4)
Which script types support the addition of Field objects in SuiteScript?
What parameters are required when defining a Field object in SuiteScript?
How do character limits differ between fields created with SuiteScript and SuiteBuilder?
How can custom options be added to a select field in SuiteScript?
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