简体   繁体   中英

TypeError: Cannot call method "split" of undefined in SuiteScript

I am new to scripting and I am trying to create a script in Netsuite that would look at the lines in a sales order and verify if there's a discount item. If there's a discount item, then the script looks at the item just before it, takes the value for field class and updates the discount item's class. I am getting Cannot call method "split" of undefined as an error and I am unsure why.

/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */
define(["N/record"], function (r){
    function afterSubmitUpdateDiscountClass(context) {

        var currentRecord = context.currentRecord;
        var numLines = currentRecord.getLineCount({
            sublistId: 'item'});

        for(var i=0; i < numLines; i++) {
            var currentItemType = currentRecord.getCurrentSublistValue ({
                sublistID: 'item',
                fieldID: 'itemType',
                line: i});

            if (currentItemType == 'discountitem') {
                var newClass = currentRecord.getCurrentSublistValue ({
                    sublistID : 'item',
                    fieldID: 'class',
                    line: i-1});
                currentRecord.selectLine({
                    sublistID: 'item',
                    line: i })
                currentRecord.setCurrentSublistValue ({
                    sublistID : 'item',
                    fieldID: 'class',
                    value : newClass });

                currentRecord.commitLine({
                    sublistID: 'item' });

            }
        }
    }
    return {
        afterSubmit: afterSubmitUpdateDiscountClass
    }
})

Try deleting the script record and recreating it. There have been reports in Slack about that error recently and recreating the script record has helped a few.

前几天遇到了这个问题,我刚刚向 NetSuite 提交了一个支持案例,因为我找不到解决方法。

You are using currentRecord.getCurrentSublistValue incorrectly. getCurrentSublistValue has no line property and is used on dynamic records after record.selectLine

In a user event context you should be calling currentRecord.getSublistValue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM