我在用户事件脚本中传递脚本参数时遇到问题。我知道为什么我的代码失败了。有什么方法可以通过参数传递文本?
这是错误:
{“类型”:“ error.SuiteScriptError”,“名称”:“ INVALID_INITIALIZE_REF”,“消息”:“您无法初始化发票:无效引用18349。”,“堆栈”:[“ createError(N / error )“,” afterSubmit(/SuiteScripts/complexInvoice.js:29)“]”“原因”:{“类型”:“内部错误”,“代码”:“ INVALID_INITIALIZE_REF”,“详细信息”:“您无法初始化发票:无效的参考18349。“,” userEvent“:” aftersubmit“,” stackTrace“:[” createError(N / error)“,” afterSubmit(/SuiteScripts/complexInvoice.js:29)“],” notifyOff“:false} ,“ id”:“”,“ notifyOff”:false}
这是代码:
/ ** * @NApiVersion 2.x * @NScriptType UserEventScript * @NModuleScope SameAccount * / define([[N / record“,” N / log“,” N / runtime“],函数(记录,日志,运行时){
function afterSubmit(context) {
// Gather your variables
var newRec = context.newRecord;
var freightCost = newRec.getValue({
fieldId: 'custbody_freight_cost'
});
var freightItem = runtime.getCurrentScript().getParameter('custscript_freight_item');
var handlingItem = runtime.getCurrentScript().getParameter('custscript_handling_item');
var salesOrderId = newRec.getValue({
fieldId: 'createdfrom'
});
log.debug('Sales Order ID', salesOrderId);
log.error({
title: 'Freight Cost',
details: freightCost
});
log.error({
title: 'Freight Item',
details: freightItem
});
// Transform the Sales Order into an Invoice
var invoiceRecord = record.transform({
fromType: record.Type.SALES_ORDER,
fromId: salesOrderId,
toType: record.Type.INVOICE,
isDynamic: true
});
log.error({
title: 'Debug Entry',
details: invoiceRecord
});
invoiceRecord.selectNewLine({
sublistId: 'item'
});
invoiceRecord.setCurrentSublistText({
sublistId: 'item',
fieldId: 'item',
text: freightItem
});
invoiceRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'amount',
value: freightCost
});
invoiceRecord.commitLine({
sublistId: 'item'
});
invoiceRecord.selectNewLine({
sublistId: 'item'
});
invoiceRecord.setCurrentSublistText({
sublistId: 'item',
fieldId: 'item',
text: handlingItem
});
invoiceRecord.commitLine({
sublistId: 'item'
});
// Here is how you set a body field
invoiceRecord.setValue({
fieldId: 'custbody_freight_cost',
value: freightCost,
ignoreFieldChange: true
});
// Submit the record
var rid = invoiceRecord.save();
log.debug('Saved Record', rid);
}
return {
afterSubmit: afterSubmit
};
});
答案 0 :(得分:0)
很可能您的销售订单18349
处于不宜开票状态,例如待批准。
答案 1 :(得分:0)
检查一下是否可行。
要解决此问题,请导航至: (1)设置>会计>首选项>设置会计>订单管理选项卡>开票 (2)启用“履行前的发票”首选项 (3)保存首选项
保存首选项后,上面的示例脚本应该能够转换销售订单。