Netsuite 项目履行到发票

Netsuite 项目履行到发票,netsuite,suitescript2.0,Netsuite,Suitescript2.0,我正在尝试将项目履行转换为发票。我创建了一个名为“运费成本”的自定义字段,我试图获取该字段的值并将其转移到发票,并在项目子列表中添加两行:“运费”和“处理”。但是,当我尝试获取运费成本的值时,我遇到了一个错误 这是我的密码: /** *@NApiVersion 2.x *@NScriptType UserEventScript *@NModuleScope SameAccount */ 定义(['N/record','N/log'] 功能(记录、日志){ })) 下面是我得到的错误: org.m

我正在尝试将项目履行转换为发票。我创建了一个名为“运费成本”的自定义字段,我试图获取该字段的值并将其转移到发票,并在项目子列表中添加两行:“运费”和“处理”。但是,当我尝试获取运费成本的值时,我遇到了一个错误

这是我的密码:

/** *@NApiVersion 2.x *@NScriptType UserEventScript *@NModuleScope SameAccount */ 定义(['N/record','N/log']

功能(记录、日志){

}))

下面是我得到的错误:


org.mozilla.javascript.EcmaError:TypeError:无法调用未定义(/SuiteScripts/complexInvoice.js#12)的方法“getValue”

出现该错误的原因是,您正在调用
记录
对象上的
.getValue
方法,而不是
orderId
对象。我建议重命名变量,以避免一些混乱,如下所述

我在这个脚本中看到的另一个问题是,在SuiteScript中不允许您将项目履行转换为发票。您只能将销售订单转换为发票。如果您想查看可以在SuiteScript中进行的所有可能转换,请打开NetSuite帮助并搜索
记录。转换(选项)

最后,看起来您正在以一种不同寻常的方式将子列表行添加到新发票中。有关如何在“动态”模式下将行添加到发票记录的示例,请参阅下面的代码


谢谢。但是,我仍然收到一个错误:me:“SSS\u无效的子列表\u操作”,“消息”:“您尝试了一个无效的子列表或行项目操作。您正在尝试访问一个不存在的行上的字段,或者您正在尝试从静态子列表添加或删除行。”,“堆栈”:有趣。您能提供错误的堆栈跟踪吗?我确实在我的帐户中测试了这个脚本,它似乎按照预期工作。您确定发票上没有运行其他脚本可能会影响此操作吗?结果是我运行了另一个脚本,谢谢。现在我得到了这个错误:{“type”:“error.suiteScriptorror”,“name”:“SSS_MISSING_REQD_参数”,“message”:“transform:MISSING a required参数:fromId”,“stack”:[“createError(N/error)”,“afterSubmit(/SuiteScripts/complexInvoice.js:24)”,“createError(N/error)”,“cause”:{“name”:“SSS_MISSING_REQD_参数”,“message”:”::“transform:缺少必需的参数:fromId”},“id”:““notifyOff”:false}您可以尝试将销售订单id像这样记录在该块之后:
var saleOrderID=newRec.getValue
log.debug('Sales Order id,saleOrderId)
({//这里我们得到的是要在转换函数fieldId中使用的销售订单id:'createdfrom'});
?此变量中必须包含某些内容。如果在根据销售订单创建的项目履行记录上运行此变量,则每次都应填写此变量。是的,没有任何内容。程序没有读取任何销售订单id值
function afterSubmit(context) {
    var orderId = context.newRecord;
    var freightCost = orderId.record.getValue({
        fieldId:'custbody_freight_cost'
    });
    log.error({
        title: 'Freight Cost',
        details: freightCost
    });
    var invoiceRecord = record.transform({
        fromType: record.Type.ITEM_FULFILLMENT,
        fromId: orderId,
        toType: record.Type.INVOICE,
        isDynamic: true
    });
    log.error({
        title: 'Debug Entry',
        details: invoiceRecord
    });
    var freightLine = invoiceRecord.insertLine({
        sublistId:'item',
        item: 3,
        ignoreRecalc: true
    });
    var handlingLine = invoiceRecord.insertLine({
        sublistId:'item',
        item: 4,
        ignoreRecalc: true
    });
    var freightSaver = invoiceRecord.setCurrentSublistValue({
        sublistId:'item',
        fieldId:'custbody_freight_cost',
        value: freightCost,
        ignoreFieldChange: true
    });
    var rid = invoiceRecord.save();
}

return {
    afterSubmit: afterSubmit
};
/** 
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
*/
define(["N/record", "N/log"], function (record, log) {

    function afterSubmit(context) {

        // Gather your variables
        var newRec = context.newRecord;
        var freightCost = newRec.getValue({
            fieldId: 'custbody_freight_cost'
        });
        var salesOrderId = newRec.getValue({ // Here we are getting the sales order id to use in the transform function
            fieldId: 'createdfrom'
        });
        log.error({
            title: 'Freight Cost',
            details: freightCost
        });

        // Transform the Sales Order into an Invoice
        var invoiceRecord = record.transform({
            fromType: record.Type.SALES_ORDER,
            fromId: salesOrderId,
            toType: record.Type.INVOICE,
            isDynamic: true
        });
        log.error({
            title: 'Debug Entry',
            details: invoiceRecord
        });

        // Add lines to the invoice like this, this is the correct way when the record is in "dynamic" mode
        invoiceRecord.selectNewLine({
            sublistId: 'item'
        });
        invoiceRecord.setCurrentSublistValue({
            sublistId: 'item',
            fieldId: 'item',
            value: 3
        });
        invoiceRecord.commitLine({
            sublistId: 'item'
        });
        invoiceRecord.selectNewLine({
            sublistId: 'item'
        });
        invoiceRecord.setCurrentSublistValue({
            sublistId: 'item',
            fieldId: 'item',
            value: 4
        });
        invoiceRecord.commitLine({
            sublistId: 'item'
        });

        // Here is how you set a body field
        invoiceRecord.setValue({
            fieldId: 'custbody_freight_cost',
            value: freightCost,
            ignoreFieldChange: true
        });

        // Submit the record
        var rid = invoiceRecord.save();
        log.debug('Saved Record', rid);
    }
    return { afterSubmit: afterSubmit };
});