When building a Suitelet using the NetSuite SuiteScript 2.x API, you may encounter this common error: “Missing a required argument: options.value”.
This usually means that at least one setSublistValue() call is receiving an undefined or null value.
Even if you believe your data exists, this error can still happen when:
- A search column returns no value.
- There is a column name mismatch.
- The field is empty in some records.
- The value type is not compatible.
The setSublistValue() method requires a valid value. Passing:
- undefined
- null
- An incompatible type
will immediately trigger an error.
This is especially common when pulling data from:
- search.create()
- result.getValue()
Because it will return null when a field is empty.
Sample Usage
The sample script below logs values before setting them and only sets a value if it has been safely converted to a string, helping avoid the error entirely.
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
define(['N/search', 'N/ui/serverWidget', 'N/log'], function(search, serverWidget, log) {
/**
* Converts null/undefined to empty string for Suitelet sublists.
* @param {any} val
* @returns {string}
*/
function safeValue(val) {
return (val !== undefined && val !== null) ? String(val) : '';
}
/**
* Main Suitelet entry point
*/
function onRequest(context) {
// Create a Suitelet form to display customer data
var form = serverWidget.createForm({ title: 'Customer List' });
// Add a list-type sublist to the form to represent the customer table
var sublist = form.addSublist({
id: 'custpage_customersublist',
type: serverWidget.SublistType.LIST,
label: 'Customers'
});
// Define display columns for the sublist
sublist.addField({
id: 'custpage_entityid',
label: 'Entity ID',
type: serverWidget.FieldType.TEXT
});
sublist.addField({
id: 'custpage_email',
label: 'Email',
type: serverWidget.FieldType.TEXT
});
sublist.addField({
id: 'custpage_phone',
label: 'Phone',
type: serverWidget.FieldType.TEXT
});
// Create a Customer search with the desired columns
var customerSearch = search.create({
type: search.Type.CUSTOMER,
columns: [
search.createColumn({ name: 'entityid' }),
search.createColumn({ name: 'email' }),
search.createColumn({ name: 'phone' })
]
});
// Get the first 10 search results
var results = customerSearch.run().getRange({ start: 0, end: 10 }) || [];
// Loop through each result and safely set sublist values
results.forEach(function(result, i) {
// Always sanitize the value to an empty string if null/undefined
var entityid = safeValue(result.getValue({ name: 'entityid' }));
var email = safeValue(result.getValue({ name: 'email' }));
var phone = safeValue(result.getValue({ name: 'phone' }));
// Log the actual values used for this line
log.debug('Row ' + i, 'entityid: "' + entityid + '", email: "' + email + '", phone: "' + phone + '"');
// Defensive coding: wrap every setSublistValue in try/catch in case a failure occurs
try {
sublist.setSublistValue({
id: 'custpage_entityid',
line: i,
value: entityid
});
} catch (e) {
log.error('Unable to set entityid at line ' + i, e.message);
}
try {
sublist.setSublistValue({
id: 'custpage_email',
line: i,
value: email
});
} catch (e) {
log.error('Unable to set email at line ' + i, e.message);
}
try {
sublist.setSublistValue({
id: 'custpage_phone',
line: i,
value: phone
});
} catch (e) {
log.error('Unable to set phone at line ' + i, e.message);
}
});
// Render the form with the populated sublist
context.response.writePage(form);
}
// Expose the Suitelet function
return { onRequest: onRequest };
});
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.
Do you have another way on how to automate your transactions using SuiteScript? Feel free to share them here!