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
        };
    });
Add Comment
2 Answers

Go through the documentation of Field.getSelectOptions to see the limitations associated with it.

Intermediate Answered on May 12, 2021.

i did  but , but did not find anything wrong

on May 16, 2021.

If you dont know which record mode is used in user event scripts, use Record.isDynamic

on May 18, 2021.

I tried ,it did not work

on May 23, 2021.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.