传递脚本参数

时间:2018-08-16 03:38:36

标签: javascript netsuite suitescript2.0

在传递此代码的脚本参数时遇到一些麻烦。该代码似乎未从以下执行日志和错误消息中读取参数的任何值:https://photos.app.goo.gl/FXKYkFAXMctP4WhY6

/ **  * @NApiVersion 2.x  * @NScriptType UserEventScript  * @NModuleScope SameAccount * / define([[N / record“,” N / log“,” N / runtime“],函数(记录,日志,运行时){

function afterSubmit(context) {

    // Gather your variables
    var newRec = context.newRecord;
    var freightCost = newRec.getValue({
        fieldId: 'custbody_freight_cost'
    });
    var freightItem = runtime.getCurrentScript().getParameter('custscript_freight_item');
    var handlingItem = runtime.getCurrentScript().getParameter('custscript_handling_item');
    var salesOrderId = newRec.getValue({
        fieldId: 'createdfrom'
    });
    log.debug('Sales Order ID', salesOrderId);
    log.error({
        title: 'Freight Cost',
        details: freightCost
    });
    log.error({
        title: 'Freight Item',
        details: freightItem
    });

    // 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
    });
    invoiceRecord.selectNewLine({
        sublistId: 'item'
    });
    invoiceRecord.setCurrentSublistText({
        sublistId: 'item',
        fieldId: 'item',
        text: freightItem
    });
    invoiceRecord.setCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'amount',
        value: freightCost
    });
    invoiceRecord.commitLine({
        sublistId: 'item'
    });
    invoiceRecord.selectNewLine({
        sublistId: 'item'
    });
    invoiceRecord.setCurrentSublistText({
        sublistId: 'item',
        fieldId: 'item',
        text: handlingItem
    });
    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 
    };

});

2 个答案:

答案 0 :(得分:0)

您可以尝试像这样将对象传递到getParameter函数中吗?

var freightItem = runtime.getCurrentScript().getParameter({ name: 'custscript_freight_item' });

答案 1 :(得分:0)

由于您的错误代码是“ INVALID_RCRD_TRANSFORM”,因此可能是您的销售订单无法转换为发票的问题。这可能是因为您记录中的“ createdfrom”字段不是销售订单,或者该订单的发票状态不正确。

确保您的createdFrom确实是一个销售订单。否则,您的销售订单可能根本无法处于开具发票的正确状态。看看埃里克(Eric)关于这个问题的答案:Transform sales order to invoice error