在 suitescript 2.0 中从销售订单生成发票时出错?

Error in generating invoice from sales order in suitescript 2.0?

我试图在销售订单中包含一个按钮(根据用户事件创建)。单击它后,将生成发票。一旦按下按钮,就会出现错误并且不会生成发票。谁能帮我解决这个问题?

    //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":"You must enter at least one line item for this transaction.","stack":["anonymous(N/serverRecordService)","onRequest(/SuiteScripts/button SL.js:39)"],"cause":{"type":"internal error","code":"USER_ERROR","details":"You must enter at least one line item for this transaction.","userEvent":null,"stackTrace":["anonymous(N/serverRecordService)","onRequest(/SuiteScripts/button SL.js:39)"],"notifyOff":false},"id":"","notifyOff":false,"userFacing":false}

正如错误所说至少包含 1 行,但我希望它自动生成。我是 suitescript 的新手,正在从文档中获取所有帮助。谁能指导我我做错了什么? 谢谢你

您需要将 SO 状态设为待结算。如果 SO 的状态为待完成,则没有行项目准备好开票。