NetSuite Scripting 2.X – 上传脚本文件 – UNEXPECTED_ERROR

huangapple go评论57阅读模式
英文:

NetSuite Scripting 2.X - Upload Script File - UNEXPECTED_ERROR

问题

我正在尝试将一个.js文件(我的Suite脚本)上传到NetSuite,但出现以下错误。

> 评估脚本时出错:
> {"type":"error.SuiteScriptModuleLoaderError","name":"UNEXPECTED_ERROR","message":"缺少
> 语句前的分号 (SS_SCRIPT_FOR_METADATA#15)","stack":[]}

问题中的脚本:

/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 */

define([ 'N/record' ],function(record) {
    function afterSubmit(context) {
        
        // Load the record.
        var rec = record.load({
            type: record.Type.INVENTORY_ITEM,
            id: 4918
        });

        let pricing_group = rec.getValue({
            fieldId: 'pricinggroup'
        });

        if (pricing_group == '') return;

        let current_desc = rec.getValue({
            fieldId: 'salesdescription'
        });

        rec.setValue({
            fieldId: 'salesdescription',
            value: pricing_group + ' | ' + current_desc,
            ignoreFieldChange: true,
            forceSyncSourcing: true
        });
     
        // Save the record.
        try {
            var recId = rec.save();

            log.debug({
                title: '记录成功更新',
                details: 'Id: ' + recId
            });

        } catch (e) {
                log.error({
                    title: e.name,
                    details: e.message
                });
        }
    }
    return {
        afterSubmit: afterSubmit
    };
});

语法是正确的,我在语法验证器上运行它,所以我不确定哪里缺少了分号。

英文:

I am trying to upload a .js file (my suite script) on to NetSuite but am getting the following error.

> Fail to evaluate script:
> {"type":"error.SuiteScriptModuleLoaderError","name":"UNEXPECTED_ERROR","message":"missing
> ; before statement (SS_SCRIPT_FOR_METADATA#15)","stack":[]}

NetSuite Scripting 2.X – 上传脚本文件 – UNEXPECTED_ERROR

The Script in question:

/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 */

    define([ 'N/record' ],function(record) {
        function afterSubmit(context) {
            
            // Load the record.
            var rec = record.load({
                type: record.Type.INVENTORY_ITEM,
                id: 4918
            });
    
            let pricing_group = rec.getValue({
                fieldId: 'pricinggroup'
            });
    
            if (part_group == '') return;
    
            let current_desc = rec.getValue({
                fieldId: 'salesdescription'
            });
    
            rec.setValue({
                fieldId: 'salesdescription',
                value: pricing_group + ' | ' + current_desc,
                ignoreFieldChange: true,
                forceSyncSourcing: true
            });
     
            // Save the record.
            try {
                var recId = rec.save();
    
                log.debug({
                    title: 'Record updated successfully',
                    details: 'Id: ' + recId
                });
    
            } catch (e) {
                    log.error({
                        title: e.name,
                        details: e.message
                    });
            }
        }
        return {
            afterSubmit: afterSubmit
        };
    });

The syntax is correct running it on a syntax validator so I'm not sure where ';' is missing.

答案1

得分: 2

您的脚本中存在一些语法错误(这些错误在SuiteScript 2.0中是错误的,但在2.1中不是,具体来说,您正在使用不在SuiteScript 2.0中有效的let关键字)。实际的错误是其中之一。

尝试这样做:

/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/

define(['N/record'], function(record) {
    function afterSubmit(context) {

        // Load the record.
        var rec = record.load({
            type: record.Type.INVENTORY_ITEM,
            id: 4918
        });

        var pricing_group = rec.getValue({
            fieldId: 'pricinggroup'
        });

        if (part_group == '') return;

        var current_desc = rec.getValue({
            fieldId: 'salesdescription'
        });

        rec.setValue({
            fieldId: 'salesdescription',
            value: pricing_group + ' | ' + current_desc,
            ignoreFieldChange: true,
            forceSyncSourcing: true
        });

        // Save the record.
        try {
            var recId = rec.save();

            log.debug({
                title: 'Record updated successfully',
                details: 'Id: ' + recId
            });
        } catch (e) {
            log.error({
                title: e.name,
                details: e.message
            });
        }
    }
    return {
        afterSubmit: afterSubmit
    };
});
英文:

You have some syntax errors in your script (which are errors in SuiteScript 2.0, but not 2.1, namely you are using the let keyword, which is not valid in SuiteScript 2.0). The error actually is about one of them.

Try this:

/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/

define([ 'N/record' ],function(record) {
    function afterSubmit(context) {

        // Load the record.
        var rec = record.load({
            type: record.Type.INVENTORY_ITEM,
            id: 4918
        });

        var pricing_group = rec.getValue({
            fieldId: 'pricinggroup'
        });

        if (part_group == '') return;

        var current_desc = rec.getValue({
            fieldId: 'salesdescription'
        });

        rec.setValue({
            fieldId: 'salesdescription',
            value: pricing_group + ' | ' + current_desc,
            ignoreFieldChange: true,
            forceSyncSourcing: true
        });

        // Save the record.
        try {
            var recId = rec.save();

            log.debug({
                title: 'Record updated successfully',
                details: 'Id: ' + recId
            });
        } catch (e) {
            log.error({
                title: e.name,
                details: e.message
            });
        }
    }
    return {
        afterSubmit: afterSubmit
    };
});

huangapple
  • 本文由 发表于 2023年5月29日 10:57:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76354438.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定