将销售订单转换为发票给Netsuite

时间:2018-06-28 20:45:15

标签: netsuite

我无法使用Suitescript将销售订单转换为发票订单。这是我的代码:

/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */
define(['N/record'],
function(record) {
    function afterSubmit(context) {
        var orderId = context.newRecord.id;
        var invoiceRecord = record.transform({
            fromType: record.Type.SALES_ORDER,
            fromId: orderId,
            toType: record.Type.INVOICE,
            isDynamic: true
        });
    }

    return {
        afterSubmit: afterSubmit
    };
});

这是我得到的错误:

Account: TSTDRV1714128
Environment: Production
Date & Time: 6/28/2018 12:56 pm
Record Type: Item Shipment
Internal ID: 16547
Execution Time: 0.00s
Script Usage: 0
Script: invoiceCreator
Type: User Event
Function: afterSubmit
Error: JS_EXCEPTION
{"type":"error.SuiteScriptError","name":"INVALID_INITIALIZE_REF","message":"You can not initialize invoice: invalid reference 16547.","stack":["createError(N/error)","afterSubmit(/SuiteScripts/UserEventScript.js:13)"],"cause":{"type":"internal error","code":"INVALID_INITIALIZE_REF","details":"You can not initialize invoice: invalid reference 16547.","userEvent":"aftersubmit","stackTrace":["createError(N/error)","afterSubmit(/SuiteScripts/UserEventScript.js:13)"],"notifyOff":false},"id":"","notifyOff":false}

我已经看到一些解决此问题的示例解决方案,但我仍然不断遇到相同的错误。帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

您看到的错误可能是由于多种原因造成的。 两种最常见的是:

  • 您的订单的发票状态不正确。您可能需要先完成它或设置您的帐户以启用“预付款发票”
  • 您的订单可能意味着要进行现金销售。如果采用付款方式,通常是现金出售,而不是发票。

我经常在转换周围使用try catch块,并在转换为客户帐单时“猜测”。根据条款和付款方式,我将尝试使用发票或现金销售作为客户账单交易类型,如果这不起作用,我将尝试其他客户账单交易类型。