In our previous article, New to NetSuite | Understanding SuiteScript 2.x Modules, we explored the SuiteScript Modules and N/record module, New to NetSuite | N/record Module Overview, which is used to interact with records. Now, we will take a closer look at one of the members of N/record: Field.getSelectOptions(options) Method.
The Field.getSelectOptions(options) is a method on the record.Field object. It returns the available choices for a dropdown select, multi-select, or radio field. Each returned option contains the option’s internal value and display text, for example:
[
{ value: 5, text: 'abc' },
{ value: 6, text: '123' }
]
It returns the field option internal ID and label as name/value pairs, must be used only on a record in dynamic mode, has no governance cost, and is supported in client and server scripts.
Syntax
var options = objField.getSelectOptions({
filter: 'C',
operator: 'startswith'
});
Parameters
For N/record, the options object uses:
{
filter: string,
operator: string
}
- Filter is the search text used to limit returned options. The filter is case-insensitive.
- Operator controls how the filter is applied and supports contains, is, and startswith; These lists contains as the default and required.
Sample Script
/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
*/
define(['N/record', 'N/log'], function(record, log) {
function execute(context) {
// Load the Sales Order in dynamic mode.
// getSelectOptions() requires dynamic mode.
var salesOrder = record.load({
type: record.Type.SALES_ORDER,
id: 25105, //SO Internal ID
isDynamic: true
});
// Get the entity field.
// On a Sales Order, entity is the Customer field.
var entityField = salesOrder.getField({
fieldId: 'entity'
});
// Get matching dropdown options from the entity field.
// This example gets entities that start with "C".
var matchingOptions = entityField.getSelectOptions({
filter: 'C',
operator: 'startswith'
});
// Log the matching entity options.
log.debug({
title: 'Matching Entity Options',
details: matchingOptions
});
}
return {
execute: execute
};
});
This Scheduled Script loads Sales Order internal ID 275 in dynamic mode, gets the Entity field, retrieves Entity/Customer options that start with C, and writes the result to the Execution Log. Replace 275 with your actual Sales Order internal ID.
DISCLAIMER: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Oracle + NetSuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.
Oracle + NetSuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Oracle + NetSuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.
Oracle + NetSuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.
To know more about deploying SuiteScript, check these New to NetSuite Articles.
In upcoming articles, we'll break down individual SuiteScript 2.x modules and explain how to use them effectively in your scripts in SuiteCloud Product Area. Stay updated by following the New to NetSuite > SuiteCloud category to receive notifications whenever new articles are published.