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.

·3 min read·View Oracle Docs

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:

ParameterTypeRequired/OptionalDescription
options.idstringRequiredThe internal ID for this field. Must be in lowercase and follow the appropriate naming structure (e.g., custpage_example).
options.labelstringRequiredThe display label for the field that users will see.
options.typestringRequiredThe field type, defined by the serverWidget.FieldType enum (e.g., TEXT, SELECT).
options.sourcestringOptionalThe 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 source parameter to NULL, and then using the Field.addSelectOption(options) method to define these options.

Code Sample

Here is an example illustrating the syntax for adding a field to a form:

suitescript
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 code

This 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?
The supported script types for adding Field objects are Suitelets and User Event Scripts, specifically at the beforeLoad entry point.
What parameters are required when defining a Field object in SuiteScript?
When defining a Field object, the required parameters include 'options.id' for the internal ID, 'options.label' for the field label, and 'options.type' for the field type. 'options.source' is optional and used for select or multi-select fields.
How do character limits differ between fields created with SuiteScript and SuiteBuilder?
Fields created with SuiteScript have a character limit of 100,000, while fields created with SuiteBuilder can have up to 1,000,000 characters.
How can custom options be added to a select field in SuiteScript?
To add custom options to a select field, you should set the 'source' parameter to NULL and then use the 'Field.addSelectOption(options)' method to define the custom options.
Source: Syntax 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 Platform

View all Platform articles →