将销售订单转换为发票错误

Transform sales order to invoice error

我在尝试将新创建的销售订单转换为发票时遇到错误。

这是我的代码:

  define(["N/log", "N/email", "N/record"], function(log, email, record) {

    function afterSubmit(scriptContext) {

        var newOrderId = scriptContext.newRecord.id;

        var objRecord = record.transform({
            fromType: record.Type.SALES_ORDER,
            fromId: newOrderId,
            toType: record.Type.INVOICE,
            isDynamic: true
        });

错误详情如下:

Account: 3671783
Environment: SandBox
Date & Time: 6/28/2017 2:09 am
Record Type: Sales Order
Internal ID: 668978
Execution Time: 0.00s
Script Usage: 0
Script: test send invoice
Type: User Event
Function: afterSubmit
Error: JS_EXCEPTION
{"type":"error.SuiteScriptError","name":"INVALID_INITIALIZE_REF","message":"You can not initialize invoice: invalid reference 668978.","stack":["createError(N/error.js)","afterSubmit(/SuiteScripts/sendinvoice1.js:23)"],"cause":{"type":"internal error","code":"INVALID_INITIALIZE_REF","details":"You can not initialize invoice: invalid reference 668978.","userEvent":"aftersubmit","stackTrace":["createError(N/error.js)","afterSubmit(/SuiteScripts/sendinvoice1.js:23)"],"notifyOff":false},"id":"","notifyOff":false}

我不知道我做错了什么。

当您尝试转换销售订单时,它处于什么状态?在您可以为 SO 开具发票之前,在特定条件下必须满足一些标准:

  • 如果您有销售订单的批准,那么您的 SO 必须先获得批准才能开具发票。
  • 如果 SO 上的任何项目是可履行的,则必须先履行订单(即具有关联的项目履行),然后才能为其开具发票
    • 除非您启用了发货前发票设置(设置>会计>会计首选项>订单管理>发票),那么您可以放弃项目发货