我试图在销售订单中包含一个按钮(通过用户事件创建)。单击后,将生成发票。按下按钮后,就会出现错误,并且不会生成发票。有人可以帮我吗?
//Client script
function pageInit() {
}
function csForButton(ctx) {
var rec = curr.get();
var customer = rec.getValue({ "fieldId": "customer" });
log.error({
title: 'customer',
details: customer
});
var scriptURL = url.resolveScript({
"scriptId": "customscript_button_task_sl",
"deploymentId": "customdeploy_button_task_sl"
});
console.log('scriptURL', scriptURL);
window.onbeforeunload = null;
window.open(scriptURL + '&id=' + rec.id);
}
return {
pageInit: pageInit,
csForButton: csForButton
};
//用户事件脚本
function beforeLoad(ctx) {
//if (context.type == context.UserEventType.VIEW) {
addbutton(ctx);
// }
}
function addbutton(ctx) {
try {
var rec = ctx.newRecord;//record object, now we can get its properties through it(e.g. fields)
var statusOfTrans = rec.getValue({ fieldId: 'status' });
log.error('statusOfTrans', statusOfTrans);
ctx.form.clientScriptFileId = "16474"
if (ctx.type == "view" && statusOfTrans == 'Pending Fulfillment') {
ctx.form.addButton({
id: 'custpage_make_invoice',
label: 'create invoice!',
functionName: 'csForButton'
});
}
}
catch (error) {
log.error('addbutton', error);
}
}
return {
beforeLoad: beforeLoad,
}
// Suitelet脚本
function onRequest(ctx) {
try {
var req = ctx.request;
var res = ctx.response;
if (req.method == 'GET') {
var objRecord = rec.transform({
fromType: rec.Type.SALES_ORDER,
fromId: req.parameters.id,
toType: rec.Type.INVOICE,
isDynamic: true,
});
objRecord.save({
ignoreMandatoryFields: true
});
res.write({output: 'Invoice created'});
}
} catch (error) {
log.error('onRequest', error);
}
}
return {
'onRequest': onRequest
}
错误(在套件中):
{“ type”:“ error.SuiteScriptError”,“ name”:“ USER_ERROR”,“ message”:“您必须为此交易输入至少一个订单项。”,“ stack”:[“ anonymous(N / serverRecordService)“,” onRequest(/ SuiteScripts / button SL.js:39)“],”原因“:{”类型“:”内部错误“,”代码“:” USER_ERROR“,”详细信息“:”您必须输入此交易的至少一个订单项。“,” userEvent“:null,” stackTrace“:[” anonymous(N / serverRecordService)“,” onRequest(/ SuiteScripts / button SL.js:39)“],” notifyOff “:false},” id“:”“,” notifyOff“:false,” userFacing“:false}
正如错误所说,包括至少1行,但我希望它能自动生成。我是Suitescript的新手,并从文档中获取所有帮助。谁能指导我我在做什么错? 谢谢你
答案 0 :(得分:1)
您需要将SO状态设置为“待处理帐单”。如果SO的状态为“待实现”,则没有任何订单项准备开票。