Using SuiteScript to Set Values for Custom Segment Fields

When a segment is applied to a record type, it appears as a field on instances of that type. You can interact with this field as you would a custom field. To do this, you need to be able to identify both the segment and the relevant values.

As of 2018.2, a unified script ID is available for custom segment definitions. You can use a single ID to refer to a custom field related to a particular custom segment on any record type the segment is applied to. In this case, the script ID refers to a custom field and not to a particular record type. With the unified script ID, you do not need to distinguish among script ID values based on the record type you are working with.

For help working with this record in the UI, see Creating a Custom Segment.

For details, see the following topics:

Identifying a Segment Field when Using the Legacy Script ID

You identify a segment field in the same way you would a custom field: by using its field ID. To find the field ID, view an instance of the record type that you want to interact with. Click the label of the field to display a window that includes the field ID.

A Field Help popup with the Field ID highlighted.

If you have permission to view custom segment definitions, you might notice that the segment definition lists a script ID and record ID. You should not refer to either of these IDs when setting a value for the segment on a record instance.

Additionally, be aware that a single custom segment can appear on instances of multiple record types. The field ID for the segment can vary among record types. You must use the field ID as it appears on an instance of the same record type where you want your script to set a segment value.

Identifying a Segment Field when Using the Unified Script ID

If you use the unified script ID for a custom segment, the script ID refers to all custom fields for record types that the segment is applied to. In this case, you must use the ID as it appears on the custom segment record to identify any custom field on a custom segment.

The Custom Segment page with the ID field highlighted.

If the Use as Field ID box is checked, it means that you are using the unified script ID for the particular custom segment only.

Identifying a Segment Value

Typically, each custom segment includes a list of possible values. To set a value for a segment by using SuiteScript, at least one value must already have been defined for the segment.

You can reference a custom segment value by specifying either of the following:

The text label is shown in the custom segment definition and on instances of the record type where the segment has been applied. On the record instance, the segment’s values are shown in either a multi-select box or a list.

The Profit Center list field with list items highlighted.

To find a segment value’s internal ID, open the segment definition at Customization > Lists, Records, & Fields > Custom Segments. To see a list of all possible values, refer to the Values sublist. This list includes a column labeled ID, which identifies each value’s internal ID.

The Values tab with the ID column highlighted.

Code Sample

The following snippet shows how to set a value for a segment with the field ID of custbody_cseg_profitcenter. This uses the legacy script ID to refer to a transaction body field on a custom segment.

          objRecord.setText({
    fieldId: 'custbody_cseg_profitcenter',
    text: 'Outerwear',
    ignoreFieldChange: false
}); 

        

Related Topics

Creating a Custom Segment
Working with the SuiteScript Records Browser
SuiteScript Supported Records
Customization

General Notices