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

时间:2017-06-27 15:17:45

标签: netsuite suitescript suitetalk

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

这是我的代码:

  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}

我不知道自己做错了什么。

1 个答案:

答案 0 :(得分:3)

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

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