ANS-1667 · SUITESCRIPT DEVELOPMENT

How to Set Checkbox Values in a NetSuite Suitelet Sublist (SuiteScript 2.0)

When populating a Suitelet sublist checkbox field in SuiteScript 2.0, developers must use string values 'T' or 'F' instead of boolean true/false.

Short answer

When setting the value for a checkbox field within a Suitelet sublist in SuiteScript 2.0, boolean `true` or `false` values are not accepted. Instead, the `setSublistValue` method requires string representations: 'T' for checked and 'F' for unchecked. Using boolean values will result in an error, while string values will correctly populate the checkbox.

Scenario

Developers building Suitelets in NetSuite SuiteScript 2.0 often encounter issues when attempting to programmatically set the value of a checkbox field within a sublist. The expectation is that standard boolean `true` or `false` values would be accepted for checkbox fields. However, using these boolean types leads to unexpected errors when the Suitelet attempts to render or process the sublist.

Solution

When setting checkbox values in a Suitelet sublist in SuiteScript 2.0, it is crucial to use string values 'T' or 'F' rather than boolean true or false. This behavior is consistent with SuiteScript 1.0 and applies to the setSublistValue method.The following example demonstrates the correct and incorrect ways to set a checkbox value:

javascript                        var subcomponentSublist = form.addSublist({                                id: 'custpage_subcomponents',                                type: uiModule.SublistType.INLINEEDITOR,                                label: 'Subcomponents'                        });                        subcomponentSublist.addField({                                id: 'custpage_mandatory',                                label: 'Mandatory',                                type: uiModule.FieldType.CHECKBOX                        }).updateDisplayType({displayType:uiModule.FieldDisplayType.DISABLED});

Attempting to set the value with a boolean will cause an error:

javascriptsubcomponentSublist.setSublistValue({id: 'custpage_mandatory', line: 0,value: true}); //THIS WILL CRASH

The correct approach is to use the string 'T' or 'F':

javascriptsubcomponentSublist.setSublistValue({id: 'custpage_mandatory', line: 0,value: 'T'}); //THIS WILL WORK

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant