RE: Why cannot get function in getSelectOptions in suite script 2.0?
Hi All
i got this error : ” cannot find function getSelectOptions in object field , type error
the field is drop down list and it works fine in suite script 1.0, Any help please ?
/**
* @NApiVersion 2.0
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define([‘N/log’, ‘N/record’, ‘N/runtime’, ‘N/search’],
/**
* @param {log} log
* @param {record} record
* @param {runtime} runtime
* @param {search} search
*/
function(log, record, runtime, search) {
/**
* Function definition to be triggered before record is loaded.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord – New record
* @param {Record} scriptContext.oldRecord – Old record
* @param {string} scriptContext.type – Trigger type
* @Since 2015.2
*/
function beforeSubmit(scriptContext) {
try {
if (scriptContext.type == scriptContext.UserEventType.EDIT || scriptContext.type == scriptContext.UserEventType.CREATE) {
var caseRec = scriptContext.newRecord;
var status = caseRec.getText({ fieldId: ‘status’ }).toLocaleUpperCase();
var origin = caseRec.getValue({ fieldId: ‘origin’ });
log.debug({ title: ‘status’, details: status });
if (status == ‘CLOSED’) {
return;
}
if (scriptContext.type == scriptContext.UserEventType.CREATE && origin == 1) {
caseRec.setValue({
fieldId: ‘assigned’,
value: 155843
});
return;
}
var currentUserId = runtime.getCurrentUser().id;
log.debug({ title: ‘currentUserId’, details: currentUserId });
if (currentUserId == -4) {
return;
}
var currentUser = search.lookupFields({
type: search.Type.EMPLOYEE,
id: currentUserId,
columns: [‘entityid’]
});
log.debug({ title: ‘currentUser’, details: currentUser });
var assignedField = caseRec.getField({ fieldId: ‘assigned’ });
log.debug({ title: ‘assignedField’, details: assignedField });
var options = assignedField.getSelectOptions({
filter: currentUser,
operator: ‘startswith’
});
log.debug({ title: ‘options’, details: options });
if (options.length > 0) {
if (scriptContext.type == scriptContext.UserEventType.CREATE && origin != 1) {
caseRec.setValue({
fieldId: ‘assigned’,
value: currentUserId
});
}
if (scriptContext.type == scriptContext.UserEventType.EDIT) {
caseRec.setValue({
fieldId: ‘assigned’,
value: currentUserId
});
}
}
}
} catch (err) {
log.error(err.message);
}
}
return {
beforeSubmit: beforeSubmit
};
});
Try to use only getSelectionOptions() with no parameters.
There may be a difference with getSelectionOptions() and getSelectOptions({filter: '',
operator: ‘starts with’}); because the first method you can’t see in the documentation, but it works well.