【问题标题】:item fulfillment to invoice项目履行到发票
【发布时间】:2018-12-27 01:44:39
【问题描述】:

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

这是我的代码:

/** * @NApiVersion 2.x * @NScriptType 用户事件脚本 * @NModuleScope 相同帐户 */ 定义(['N/记录','N/log'],

函数(记录,日志){

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
};

});

这是我得到的错误:

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

【问题讨论】:

    标签: netsuite suitescript2.0


    【解决方案1】:

    您收到该错误的原因是您在 record 对象而不是 orderId 对象上调用 .getValue 方法。我建议重命名变量以避免混淆,如下所示。

    我在此脚本中看到的另一个问题是不允许您在 SuiteScript 中将 Item Fulfillment 转换为 Invoice。您只能将销售订单转换为发票。如果您想查看可以在 SuiteScript 中进行的所有可能的转换,请打开 NetSuite 帮助并搜索 record.transform(options)

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

    /** 
     * @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 };
    });
    

    【讨论】:

    • 谢谢。但是,我仍然收到错误消息:me":"SSS_INVALID_SUBLIST_OPERATION","message":"您尝试了无效的子列表或订单项操作。您要么尝试访问不存在的行上的字段,要么尝试从静态子列表中添加或删除行。","stack":
    • 有趣。你能提供错误的堆栈跟踪吗?我确实在我的帐户中测试了这个脚本,它似乎按预期工作。您确定发票上没有运行其他可能影响此的脚本吗?
    • 原来我运行了另一个脚本,谢谢。现在我收到此错误: {"type":"error.SuiteScriptError","name":"SSS_MISSING_REQD_ARGUMENT","message":"transform: Missing a required argument: fromId","stack":["createError( N/error)","afterSubmit(/SuiteScripts/complexInvoice.js:24)","createError(N/error)"],"cause":{"name":"SSS_MISSING_REQD_ARGUMENT","message":"transform:缺少必需的参数:fromId"},"id":"","notifyOff":false}
    • 您可以尝试像log.debug('Sales Order ID, salesOrderId) 一样在此块之后记录销售订单 ID:var salesOrderId = newRec.getValue({ // Here we are getting the sales order id to use in the transform function fieldId: 'createdfrom' });?这个变量必须有一些东西。如果您在从销售订单创建的项目履行记录上运行此操作,则应每次都填写。
    • 是的,那里什么都没有。该程序未读取销售订单 ID 的任何值
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-20
    • 2015-12-31
    相关资源
    最近更新 更多