发票的项目履行

时间:2018-07-19 03:21:12

标签: netsuite suitescript2.0

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

这是我的代码:

/ **  * @NApiVersion 2.x  * @NScriptType UserEventScript  * @NModuleScope SameAccount  * / define([['N / record','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:无法调用未定义(/SuiteScripts/complexInvoice.js#12)的方法“ getValue”

1 个答案:

答案 0 :(得分:1)

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

我看到此脚本中发生的另一个问题是不允许您在SuiteScript中将“商品实现”转换为“发票”。您只能将销售订单转换为发票。如果要查看所有可能的转换,可以在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 };
});