I'm trying to transform an item fulfillment to invoice. I created a custom field called "freight cost" and I"m trying to get the value of that field and transfer it over to the invoice and add two lines to the item sublist: "FREIGHT" and "HANDLING". However, I'm getting an error when I try to get the value of the freight cost.
Here's my code:
/** * @NApiVersion 2.x * @NScriptType UserEventScript * @NModuleScope SameAccount */ define(['N/record', 'N/log'],
function(record, 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
};
});
And here's the error I'm getting:
org.mozilla.javascript.EcmaError: TypeError: Cannot call method "getValue" of undefined (/SuiteScripts/complexInvoice.js#12)