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.
Source: This article is based on Oracle's official NetSuite documentation.
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 Platform
- Style Object Members for Workbook API in NetSuite
The Style object provides customizable properties for workbook formatting in NetSuite, enhancing report and visualization functionality.
- Asynchronous HTTP Requests with SuiteScript Promises
Use SuiteScript to send asynchronous HTTP requests with promises for efficient error handling and response processing.
- Setting Sublist Field Values in SuiteScript
Set values for sublist fields in SuiteScript using the setSublistValue method. Understand required parameters and error handling.
- In This Help Topic
Explore N/log module guidelines, log levels, and script execution logs for efficient logging in SuiteScript.
Advertising
Reach Platform Professionals
Put your product in front of NetSuite experts who work with Platform every day.
Sponsor This Category