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

问题描述 投票:1回答:1

我试图在销售订单上添加一个按钮(通过用户事件创建)。单击后,将生成发票。按下按钮后,就会出现错误,并且不会生成发票。有人可以帮我吗?

    //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“ :假}, “ID”: “”, “notifyOff”:假 “userFacing”:假}

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

javascript netsuite suitescript2.0
1个回答
0
投票

您需要将SO状态设置为“待处理帐单”。如果SO的状态为“待实现”,则没有任何发票准备就绪。

© www.soinside.com 2019 - 2024. All rights reserved.