How do I modify a transfer order when it is created via Celigo integration?
I have a SuiteScript that edits two custom fields (number of line items and total units) when a transfer order is created. It works great when a user creates the transfer order through the UI but doesn’t run when the transfer order is created by our integration with Celigo (which accounts for 99% of the TO’s we generate).
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/
define(['N/record'],
function (record) {
function afterSubmit(context) {
try {
//initialize variable for total quantity
var totalQuantity = 0;
// count number of lines in 'item' sublist
var transferOrder = context.newRecord;
var itemCount = transferOrder.getLineCount('item');
//for each line in the 'item' sublist, add value in quantity column to the total quantity variable
for (var i = 0; i < itemCount; i++) {
lineLevelQuantity = transferOrder.getSublistValue('item', 'quantity', i)
if (lineLevelQuantity != '' && lineLevelQuantity != null) {
totalQuantity += parseInt(lineLevelQuantity);
}
}
//These lines below will update these fields before the record is saved
var id = record.submitFields({
type: 'transferorder',
id: transferOrder.id,
values: {
'custbody_to_item_quantity': totalQuantity,
'custbody_to_line_items': itemCount,
'firmed': true
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
})
//Debugging if anything goes wrong
} catch (e) {
log.debug({
title: 'Error Details',
details: e
})
}
}
return {
afterSubmit: afterSubmit
};
}
);



