Netsuite 将发票转换为自定义记录计划脚本
Netsuite Transform Invoice to Custom Record Scheduled Script
我正在尝试创建一个脚本,将发票记录转换为基于 Scheduled Script
的自定义记录。
我已创建保存的搜索,但在上传 script
时收到错误消息:
Fail to evaluate script: {"type":"error.SuiteScriptModuleLoaderError","name":"UNEXPECTED_ERROR","message":"missing ) after argument list (SS_SCRIPT_FOR_METADATA#57)","stack":[]}
/**
*@NApiVersion 2.x
*@NScriptType ScheduledScript
*/
define(['N/search', 'N/record', 'N/email', 'N/runtime'],
function(search, record, email, runtime) {
function execute(context) {
if (context.type !== context.InvocationType.ON_DEMAND)
return;
var searchId = runtime.getCurrentScript().getParameter("custscript_searchid"); //add from script deployment
try {
search.load({
id: searchId
}).run().each(function(result) {
log.debug({
details: 'creating invoice to email record from INV: ' + result.id
});
var invoiceToEmail = record.transform({
fromType: record.Type.INVOICE,
fromId: result.id,
toType: record.Type.customrecord_invoice_to_email,
isDynamic: false
});
invoiceToEmail.setValue({
fieldId: custrecord_email_template,
value: //add internal id of email template to use
});
invoiceToEmail.setValue({
fieldId: custrecord_invoice_number,
value: result.id
});
invoiceToEmail.setValue({
fieldId: custrecord_script_error,
value: //create variable for script error
});
invoiceToEmail.setValue({
fieldId: custrecord_ap_contact_email,
value: //populate from result information
});
invoiceToEmail.save();
})
} catch (e) {
log.error({
title: e.name,
details: e.message
});
}
return {
execute: execute
};
}
}
不确定这是否是我做过的事情,它仍在进行中,因为我还没有为设定值定义值。
您的脚本中存在语法错误,可能是在顶级脚本本身中,也可能是在包含的模块之一中。修复语法错误,您的脚本将成功上传。
在像 WebStorm 这样好的 IDE 中开发您的代码,它可以突出显示 JavaScript 语法错误以避免此类问题。
你最后漏了一个")"
define(['N/search', 'N/record', 'N/email', 'N/runtime'],
function (search, record, email, runtime) {
function execute(context) {
if (context.type !== context.InvocationType.ON_DEMAND)
return;
var searchId = runtime.getCurrentScript().getParameter("custscript_searchid"); //add from script deployment
try {
search.load({
id: searchId
}).run().each(function (result) {
log.debug({
details: 'creating invoice to email record from INV: ' + result.id
});
var invoiceToEmail = record.transform({
fromType: record.Type.INVOICE,
fromId: result.id,
toType: record.Type.customrecord_invoice_to_email,
isDynamic: false
});
invoiceToEmail.setValue({
fieldId: custrecord_email_template,
value: //add internal id of email template to use
});
invoiceToEmail.setValue({
fieldId: custrecord_invoice_number,
value: result.id
});
invoiceToEmail.setValue({
fieldId: custrecord_script_error,
value: //create variable for script error
});
invoiceToEmail.setValue({
fieldId: custrecord_ap_contact_email,
value: //populate from result information
});
invoiceToEmail.save();
})
} catch (e) {
log.error({
title: e.name,
details: e.message
});
}
return {
execute: execute
};
}
}
)
您需要为三个字段输入值。请参考以下代码中的问题 (????) 标记。:
});
var invoiceToEmail = record.transform({
fromType: record.Type.INVOICE,
fromId: result.id,
toType: record.Type.customrecord_invoice_to_email,
isDynamic: false
});
invoiceToEmail.setValue({
fieldId: custrecord_email_template,
value: **????**//add internal id of email template to use
});
invoiceToEmail.setValue({
fieldId: custrecord_invoice_number,
value: result.id
});
invoiceToEmail.setValue({
fieldId: custrecord_script_error,
value: **????** //create variable for script error
});
invoiceToEmail.setValue({
fieldId: custrecord_ap_contact_email,
value: **????** //populate from result information
});
invoiceToEmail.save();
我正在尝试创建一个脚本,将发票记录转换为基于 Scheduled Script
的自定义记录。
我已创建保存的搜索,但在上传 script
时收到错误消息:
Fail to evaluate script: {"type":"error.SuiteScriptModuleLoaderError","name":"UNEXPECTED_ERROR","message":"missing ) after argument list (SS_SCRIPT_FOR_METADATA#57)","stack":[]}
/**
*@NApiVersion 2.x
*@NScriptType ScheduledScript
*/
define(['N/search', 'N/record', 'N/email', 'N/runtime'],
function(search, record, email, runtime) {
function execute(context) {
if (context.type !== context.InvocationType.ON_DEMAND)
return;
var searchId = runtime.getCurrentScript().getParameter("custscript_searchid"); //add from script deployment
try {
search.load({
id: searchId
}).run().each(function(result) {
log.debug({
details: 'creating invoice to email record from INV: ' + result.id
});
var invoiceToEmail = record.transform({
fromType: record.Type.INVOICE,
fromId: result.id,
toType: record.Type.customrecord_invoice_to_email,
isDynamic: false
});
invoiceToEmail.setValue({
fieldId: custrecord_email_template,
value: //add internal id of email template to use
});
invoiceToEmail.setValue({
fieldId: custrecord_invoice_number,
value: result.id
});
invoiceToEmail.setValue({
fieldId: custrecord_script_error,
value: //create variable for script error
});
invoiceToEmail.setValue({
fieldId: custrecord_ap_contact_email,
value: //populate from result information
});
invoiceToEmail.save();
})
} catch (e) {
log.error({
title: e.name,
details: e.message
});
}
return {
execute: execute
};
}
}
不确定这是否是我做过的事情,它仍在进行中,因为我还没有为设定值定义值。
您的脚本中存在语法错误,可能是在顶级脚本本身中,也可能是在包含的模块之一中。修复语法错误,您的脚本将成功上传。
在像 WebStorm 这样好的 IDE 中开发您的代码,它可以突出显示 JavaScript 语法错误以避免此类问题。
你最后漏了一个")"
define(['N/search', 'N/record', 'N/email', 'N/runtime'],
function (search, record, email, runtime) {
function execute(context) {
if (context.type !== context.InvocationType.ON_DEMAND)
return;
var searchId = runtime.getCurrentScript().getParameter("custscript_searchid"); //add from script deployment
try {
search.load({
id: searchId
}).run().each(function (result) {
log.debug({
details: 'creating invoice to email record from INV: ' + result.id
});
var invoiceToEmail = record.transform({
fromType: record.Type.INVOICE,
fromId: result.id,
toType: record.Type.customrecord_invoice_to_email,
isDynamic: false
});
invoiceToEmail.setValue({
fieldId: custrecord_email_template,
value: //add internal id of email template to use
});
invoiceToEmail.setValue({
fieldId: custrecord_invoice_number,
value: result.id
});
invoiceToEmail.setValue({
fieldId: custrecord_script_error,
value: //create variable for script error
});
invoiceToEmail.setValue({
fieldId: custrecord_ap_contact_email,
value: //populate from result information
});
invoiceToEmail.save();
})
} catch (e) {
log.error({
title: e.name,
details: e.message
});
}
return {
execute: execute
};
}
}
)
您需要为三个字段输入值。请参考以下代码中的问题 (????) 标记。:
});
var invoiceToEmail = record.transform({
fromType: record.Type.INVOICE,
fromId: result.id,
toType: record.Type.customrecord_invoice_to_email,
isDynamic: false
});
invoiceToEmail.setValue({
fieldId: custrecord_email_template,
value: **????**//add internal id of email template to use
});
invoiceToEmail.setValue({
fieldId: custrecord_invoice_number,
value: result.id
});
invoiceToEmail.setValue({
fieldId: custrecord_script_error,
value: **????** //create variable for script error
});
invoiceToEmail.setValue({
fieldId: custrecord_ap_contact_email,
value: **????** //populate from result information
});
invoiceToEmail.save();