无法评估脚本:当我上传 map/reduce 脚本时,我收到了后面的错误
Fail to evaluate script: when I upload a map/reduce script I received the error behind
错误
无法评估脚本:{"type":"error.SuiteScriptModuleLoaderError","name":"UNEXPECTED_ERROR","message":"syntax error (SS_SCRIPT_FOR_METADATA#11)","stack ":[]}
我是 suitescript 的新手,所以,我想知道 map/reduce 脚本是如何工作的,我复制了文档示例,但我收到了那个错误。
define(['N/file'], (file) => {
const PUNCTUATION_REGEXP = /[\u2000-\u206F\u2E00-\u2E7F\'!"#$%&\(\)\*\+,\-\.\/:;<=>\?@\
[\]\^_`\{\|\}~]/g;
function getInputData() {
return 'the quick brown fox \njumps over the lazy dog.'.split('\n');
}
function map(context) {
for (let i = 0; context.value && i < context.value.length; i++) {
if (context.value[i] !== ' ' && !PUNCTUATION_REGEXP.test(context.value[i])) {
context.write({
key: context.value[i],
value: 1,
});
}
}
}
function reduce(context) {
context.write({
key: context.key,
value: context.values.length,
});
}
function summarize(context) {
log.audit({
title: 'Usage units consumed',
details: context.usage,
});
log.audit({
title: 'Concurrency',
details: context.concurrency,
});
log.audit({
title: 'Number of yields',
details: context.yields,
});
let text = '';
let totalKeysSaved = 0;
context.output.iterator().each((key, value) => {
text += (`${key} ${value}\n`);
totalKeysSaved++;
return true;
});
log.audit({
title: 'Unique number of letters used in string',
details: totalKeysSaved,
});
const fileObj = file.create({
name: 'prueba_mapReduce_training_lk.txt',
fileType: file.Type.PLAINTEXT,
contents: text,
});
fileObj.folder = -15;
const fileId = fileObj.save();
log.audit({
title: 'Id of new file record',
details: fileId,
});
}
return {
getInputData,
map,
reduce,
summarize,
};
});
`
感谢您的帮助!
查看下面的标签,Map/Reduce 脚本需要它们:
/**
*@NApiVersion 2.x
*@NScriptType MapReduceScript
*/
Netsuite Suitescript 的语法与 Javascript 不完全相同。
导致问题的原因是 -
不要在定义变量时使用let。
输出迭代器循环将有一些更好的语法。 (使用 => 会出错。)请确保 (${key} ${value}\n
) 导致其出错。暂时用0代替
CORRECT SYNTAX-
context.output.iterator().each(function(key, value){
text += 0; //Some issue with (`${key} ${value}\n`) [BAD SYNTAX]
totalKeysSaved++;
return true;
});
始终包含 JSDoc
/**
*@NApiVersion 2.x
*@NScriptType MapReduceScript
*/
遵循 return 语句的规则
return {
getInputData:getInputData,
map:map,
reduce:reduce,
summarize:summarize,
}
以上是我发现的问题,请使用下面的代码进行测试。为我工作。
/**
*@NApiVersion 2.x
*@NScriptType MapReduceScript
*/
define(['N/file'], function(file) {
PUNCTUATION_REGEXP = /[\u2000-\u206F\u2E00-\u2E7F\'!"#$%&\(\)\*\+,\-\.\/:;<=>\?@\ [\]\^_`\{\|\}~]/g;
function getInputData() {
return 'the quick brown fox \njumps over the lazy dog.'.split('\n');
}
function map(context) {
for (i=0; (context.value && i) < context.value.length; i++) {
if (context.value[i] !== ' ' && !PUNCTUATION_REGEXP.test(context.value[i])) {
context.write({
key: context.value[i],
value: 1,
});
}
}
}
function reduce(context) {
context.write({
key: context.key,
value: context.values.length,
});
}
function summarize(context) {
log.audit({
title: 'Usage units consumed',
details: context.usage,
});
log.audit({
title: 'Concurrency',
details: context.concurrency,
});
log.audit({
title: 'Number of yields',
details: context.yields,
});
text = '';
totalKeysSaved = 0;
context.output.iterator().each(function(key, value){
text += 0; //Some issue with (`${key} ${value}\n`) [BAD SYNTAX]
totalKeysSaved++;
return true;
});
log.audit({
title: 'Unique number of letters used in string',
details: totalKeysSaved,
});
const fileObj = file.create({
name: 'prueba_mapReduce_training_lk.txt',
fileType: file.Type.PLAINTEXT,
contents: text,
});
fileObj.folder = -15;
const fileId = fileObj.save();
log.audit({
title: 'Id of new file record',
details: fileId,
});
}
return {
getInputData:getInputData,
map:map,
reduce:reduce,
summarize:summarize,
}
});
错误 无法评估脚本:{"type":"error.SuiteScriptModuleLoaderError","name":"UNEXPECTED_ERROR","message":"syntax error (SS_SCRIPT_FOR_METADATA#11)","stack ":[]}
我是 suitescript 的新手,所以,我想知道 map/reduce 脚本是如何工作的,我复制了文档示例,但我收到了那个错误。
define(['N/file'], (file) => {
const PUNCTUATION_REGEXP = /[\u2000-\u206F\u2E00-\u2E7F\'!"#$%&\(\)\*\+,\-\.\/:;<=>\?@\
[\]\^_`\{\|\}~]/g;
function getInputData() {
return 'the quick brown fox \njumps over the lazy dog.'.split('\n');
}
function map(context) {
for (let i = 0; context.value && i < context.value.length; i++) {
if (context.value[i] !== ' ' && !PUNCTUATION_REGEXP.test(context.value[i])) {
context.write({
key: context.value[i],
value: 1,
});
}
}
}
function reduce(context) {
context.write({
key: context.key,
value: context.values.length,
});
}
function summarize(context) {
log.audit({
title: 'Usage units consumed',
details: context.usage,
});
log.audit({
title: 'Concurrency',
details: context.concurrency,
});
log.audit({
title: 'Number of yields',
details: context.yields,
});
let text = '';
let totalKeysSaved = 0;
context.output.iterator().each((key, value) => {
text += (`${key} ${value}\n`);
totalKeysSaved++;
return true;
});
log.audit({
title: 'Unique number of letters used in string',
details: totalKeysSaved,
});
const fileObj = file.create({
name: 'prueba_mapReduce_training_lk.txt',
fileType: file.Type.PLAINTEXT,
contents: text,
});
fileObj.folder = -15;
const fileId = fileObj.save();
log.audit({
title: 'Id of new file record',
details: fileId,
});
}
return {
getInputData,
map,
reduce,
summarize,
};
});
`
感谢您的帮助!
查看下面的标签,Map/Reduce 脚本需要它们:
/** *@NApiVersion 2.x *@NScriptType MapReduceScript */
Netsuite Suitescript 的语法与 Javascript 不完全相同。
导致问题的原因是 -
不要在定义变量时使用let。
输出迭代器循环将有一些更好的语法。 (使用 => 会出错。)请确保 (
${key} ${value}\n
) 导致其出错。暂时用0代替CORRECT SYNTAX- context.output.iterator().each(function(key, value){ text += 0; //Some issue with (`${key} ${value}\n`) [BAD SYNTAX] totalKeysSaved++; return true; });
始终包含 JSDoc
/** *@NApiVersion 2.x *@NScriptType MapReduceScript */
遵循 return 语句的规则
return { getInputData:getInputData, map:map, reduce:reduce, summarize:summarize, }
以上是我发现的问题,请使用下面的代码进行测试。为我工作。
/**
*@NApiVersion 2.x
*@NScriptType MapReduceScript
*/
define(['N/file'], function(file) {
PUNCTUATION_REGEXP = /[\u2000-\u206F\u2E00-\u2E7F\'!"#$%&\(\)\*\+,\-\.\/:;<=>\?@\ [\]\^_`\{\|\}~]/g;
function getInputData() {
return 'the quick brown fox \njumps over the lazy dog.'.split('\n');
}
function map(context) {
for (i=0; (context.value && i) < context.value.length; i++) {
if (context.value[i] !== ' ' && !PUNCTUATION_REGEXP.test(context.value[i])) {
context.write({
key: context.value[i],
value: 1,
});
}
}
}
function reduce(context) {
context.write({
key: context.key,
value: context.values.length,
});
}
function summarize(context) {
log.audit({
title: 'Usage units consumed',
details: context.usage,
});
log.audit({
title: 'Concurrency',
details: context.concurrency,
});
log.audit({
title: 'Number of yields',
details: context.yields,
});
text = '';
totalKeysSaved = 0;
context.output.iterator().each(function(key, value){
text += 0; //Some issue with (`${key} ${value}\n`) [BAD SYNTAX]
totalKeysSaved++;
return true;
});
log.audit({
title: 'Unique number of letters used in string',
details: totalKeysSaved,
});
const fileObj = file.create({
name: 'prueba_mapReduce_training_lk.txt',
fileType: file.Type.PLAINTEXT,
contents: text,
});
fileObj.folder = -15;
const fileId = fileObj.save();
log.audit({
title: 'Id of new file record',
details: fileId,
});
}
return {
getInputData:getInputData,
map:map,
reduce:reduce,
summarize:summarize,
}
});