1

I have create a simple ClientScript to update a sales order sublist value from item fulfillment.
when the script run the record.save() API, I got error JS_EXCEPTION - TypeError: Cannot read property 'name' of undefined.

Here Is my Script :

/**
 *@NApiVersion 2.x
 *@NScriptType ClientScript
 */
define(['N/record', 'N/currentRecord', 'N/search', 'N/log'], function (record, currentRecord, search, log) {
    function saveRecord(context) {
        var currentRecord = context.currentRecord;

        var soId = currentRecord.getValue({
            fieldId: 'createdfrom'
        });

        var soRecord = record.load({
            type: record.Type.SALES_ORDER,
            id: soId,
            isDynamic: true
        });

        var soItemCount = soRecord.getLineCount({
            sublistId: 'item'
        });
        log.debug({
            title: "soItemCount",
            details: soItemCount
        });

        for (var so = 0; so < soItemCount; so++) {
            soRecord.selectLine({
                sublistId: 'item',
                line: so
            });

            soRecord.setCurrentSublistValue({
                sublistId: 'item',
                fieldId: 'custcol_need_approval',
                value: true
            });

            soRecord.setCurrentSublistValue({
                sublistId: 'item',
                fieldId: 'custcol_fulfill_qty',
                value: 90
            });
        }
        soRecord.commitLine({
            sublistId: 'item'
        });

    soRecord.save();

    return true;
}
    return {
    saveRecord: saveRecord
};
});

can anyone give me a suggestion with my script ?

2 Answers 2

1

Can you check if the error is form any other UserEvent script deployed on Sales order, as when you try to save the record with client script all User event scripts deployed will execute.

Try undeploying other scripts and test once to rule out error

Sign up to request clarification or add additional context in comments.

1 Comment

This is definitely indicative of an extraneous script error, possible a user event on the salesorder
0

Probably the best approach to the solution you want to make is a UserEvent with an afterSubmit event.

The solution code is going to be very similar.

/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 */
define(['N/record', 'N/search', 'N/log'], 
    function (record, search, log) {
        function afterSubmit(context) {
            var currentRecord = context.newRecord;

            var soId = currentRecord.getValue({
                fieldId: 'createdfrom'
            });

            var soRecord = record.load({
                type: record.Type.SALES_ORDER,
                id: soId,
                isDynamic: true
            });

            var soItemCount = soRecord.getLineCount({
                sublistId: 'item'
            });

            log.debug({
                title: "soItemCount",
                details: soItemCount
            });

            for (var so = 0; so < soItemCount; so++) {
                
                soRecord.setSublistValue({
                    sublistId: 'item',
                    fieldId: 'custcol_need_approval',
                    line: so,
                    value: true
                });

                soRecord.setSublistValue({
                    sublistId: 'item',
                    fieldId: 'custcol_fulfill_qty',
                    line: so,
                    value: 90
                });
                
            }       

            soRecord.save();
        }
    return {
        afterSubmit: afterSubmit
    };
});

2 Comments

Hi @Camilo, thanks for your answer, But I I think cant use After submit Script method in my case. The reason I use ClientScript is I want to develop a script which use this method (update sublist field value) in my script, the script will update the Sales Order Record when the user Click 'Yes' on a confirmation message, and then redirect user to Sales Order page without save the item fulfillment record.
I'd tend to do this sort of thing in a suitelet. Once the suitelet runs you can redirect to the SO. Dealing with sublists in client scripts tends to be slow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.