I have a legacy SuiteScript 1.0 script and I want to load a customer record and check whether a specific multiselect field has any selected values. If no values are selected, I want to add a default value.
I can load the record and verify if the field contains a value. I can add value(s) to multiselect fields in the customer record but NOT for the "leadsource" field which produces the error:
"Please enter value(s) for: Leadsource".
There seems to be something special about the "leadsource" field which requires special handling. Any ideas?
function postRESTlet(dataIn) {
var record = nlapiLoadRecord('customer', 17417);
var values = new Array();
var leadsource = record.getFieldValues('leadsource');
if(leadsource === null) {
values[0] = '-2';
record.setFieldValues('leadsource', values);
}
nsid = nlapiSubmitRecord(record);
return nsid;
}
The value of the leadsource field is supposed to be an array of strings only in case there are multiple values. Otherwise it's just sting. So just use -2
, like:
function postRESTlet(dataIn) {
var record = nlapiLoadRecord('customer', 17417);
var values = new Array();
var leadsource = record.getFieldValues('leadsource');
if(leadsource === null) {
values = '-2';
record.setFieldValues('leadsource', values);
}
nsid = nlapiSubmitRecord(record);
return nsid;
}
This will get rid of the error
"Please enter value(s) for: Leadsource"
but you may have others, e.g.
Please enter value(s) for: Invoice Email
which is out of scope of this question