// transform sales order to invoice
var transformRecord = record.transform({
fromType: 'salesorder',
fromId: soid,
toType: 'invoice',
isDynamic: true
});
// get sublist line count
var lineCount = transformRecord.getLineCount('item');
for (var j = lineCount - 1; j >= 0; j--) {
// get the line id
var lineId = transformRecord.getSublistValue('item', 'orderline', j);
// identify the line id is aviable in our so lines
var soLineRecords = soLines.filter(function(e) {
return e.lineId == lineId;
});
if (soLineRecords.length == 0) {
var item = transformRecord.getSublistText('item', 'item', j);
log.debug("removed item", item);
transformRecord.removeLine({
sublistId: 'item',
line: j,
ignoreRecalc: true
});
}
}
var invoiceId = transformRecord.save();
log.debug('invoiceId', invoiceId);