英文:
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":[]}
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
};
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论