更改代码以使用参数

时间:2018-08-07 20:26:42

标签: netsuite suitescript2.0

我正在尝试更改此代码,以便可以在Suitescript 2.0中使用参数进行货运和处理。这是我的代码:

/ **  * @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 salesOrderId = newRec.getValue({
        fieldId: 'createdfrom'
    });
    log.debug('Sales Order ID', salesOrderId);
    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
    });
    invoiceRecord.selectNewLine({
        sublistId: 'item'
    });
    invoiceRecord.setCurrentSublistText({
        sublistId: 'item',
        fieldId: 'item',
        text: 'FREIGHT'
    });
    invoiceRecord.setCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'amount',
        value: freightCost
    });
    invoiceRecord.commitLine({
        sublistId: 'item'
    });
    invoiceRecord.selectNewLine({
        sublistId: 'item'
    });
    invoiceRecord.setCurrentSublistText({
        sublistId: 'item',
        fieldId: 'item',
        text: 'HANDLING'
    });
    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 
    };

});

1 个答案:

答案 0 :(得分:1)

您将要在脚本记录上创建适当的脚本参数,在脚本部署记录上填充适当的值,然后利用N/runtime.getParameter()在运行时检索这些值。