RE: How to solve unexpected error for client script 2.0?

Hi All,

i wrote this  client script 2.0  and deployed  it  to case record

i got this error when i try to select sales order  :

An unexpected error has occurred. Please click <a href=”javascript:window.open(‘/app/crm/support/nlcorpsupport.nl?l=T&type=bug&ticket=kobcvggnjbjo4fctg0ox’, ‘Error’,’scrollbars=yes,toolbar=no,width=800,height=700′);void(0)”>here</a> to notify support and provide your contact information.

 

the code:

/**
 * @NApiVersion 2.0
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */
define([‘N/log’, ‘N/search’],
    /**
     * @param {log} log
     * @param {search} search
     */
    function(log, search) {
        function isEmpty(data) { return (data == ” || data == ‘ ‘ || data == null); };
        /**
         * Function to be executed after page is initialized.
         *
         * @param {Object} scriptContext
         * @param {Record} scriptContext.currentRecord – Current form record
         * @param {string} scriptContext.mode – The mode in which the record is being accessed (create, copy, or edit)
         *
         * @since 2015.2
         */
        function pageInit(scriptContext) {
            if (scriptContext.mode == ‘create’) {
                var currentRecord = scriptContext.currentRecord;
                var tranId = currentRecord.getValue({
                    fieldId: ‘custevent_case_orderid’
                });
                if (!isEmpty(tranId)) {
                    log.debug({ title: ‘Type’, details: scriptContext.mode + ‘ ‘ + ‘SOR’ + ‘ ‘ + tranId });
                    var customer = search.lookupFields({
                        type: search.Type.SALES_ORDER,
                        id: tranId,
                        columns: [‘entity’]
                    });
                    currentRecord.setValue({
                        fieldId: ‘company’,
                        value: customer
                    });
                }
            }
            return true;
        }
        /**
         * Validation function to be executed when field is changed.
         *
         * @param {Object} scriptContext
         * @param {Record} scriptContext.currentRecord – Current form record
         * @param {string} scriptContext.sublistId – Sublist name
         * @param {string} scriptContext.fieldId – Field name
         * @param {number} scriptContext.lineNum – Line number. Will be undefined if not a sublist or matrix field
         * @param {number} scriptContext.columnNum – Line number. Will be undefined if not a matrix field
         *
         * @returns {boolean} Return true if field is valid
         *
         * @since 2015.2
         */
        function validateField(scriptContext) {
            var currentRecord = scriptContext.currentRecord;
            if (scriptContext.fieldId == ‘custevent_case_orderid’) {
                var sorId = currentRecord.getValue({
                    fieldId: ‘custevent_case_orderid’
                });
                if (!isEmpty(sorId)) {
                    var sorCustomer = search.lookupFields({
                        type: search.Type.SALES_ORDER,
                        id: sorId,
                        columns: [‘entity’]
                    });
                    currentRecord.setValue({
                        fieldId: ‘company’,
                        value: sorCustomer
                    });
                }
            }
            return true;
        }
        return {
            pageInit: pageInit,
            validateField: validateField
        };
    });

 

 

Add Comment
1 Answers

Inspect the return value of search.lookupFields. Its return value is an object that can’t be used as the value of setValue.

Intermediate Answered on May 5, 2021.

Thank you

from the search.lookupFields i got

{“entity”:[{“value”:”17781″,”text”:”CST000005265 Yosser Ben Mena BenAbdallah”}]}

how i can choose the correct value from the entity to use it to set value?

on May 5, 2021.

It’s an array of objects, you get the value from it the exact same way you get any value from an array of objects.

on May 5, 2021.
Add Comment

Your Answer

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