Gail Kasnett
06/26/2022, 10:36 AMfor (il = 0; il < items_by_location.length; il++) {
var item_loc = ''
item_loc = items_by_location[il]
if (item_loc.location == loc) {
loc_items.push(item_loc)
}
}
log.debug('total location items: ' + loc_items.length)
if (loc_items.length == 0) { continue }
log.debug('loc_items: ', loc_items)
// var fulfillment = ''
//transform SO to create a new Item fulfillment
// try {
var fulfillment = record.transform({
fromType: record.Type.SALES_ORDER,
fromId: sales_order.id,
toType: record.Type.ITEM_FULFILLMENT,
isDynamic: true
});
log.debug('got past transform')
// } catch (err) {
// var subj = 'Failed to transform ' + transaction_id + ' to IF'
// var msg = err.message
// sendEmail_forceSenderReceiver(subj, msg)
// }
log.debug('fulfillment', fulfillment)
//get line count of newly created fulfillment
var lineCount = fulfillment.getLineCount('item');
log.debug('fulfillment line count', lineCount)
for (li = 0; li < loc_items.length; li++) {
var loc_item = loc_items[li]
log.debug('loc_item', loc_item)
if (loc_item.committedQty < loc_item.qty) {
log.debug(loc.item_name + ' is on BackOrder. Not Creating fulfillment for these items')
email_message += '</ br> Sales Order: ' + sales_order.id + ', Location: ' + loc + ' not creating an IF right now because ' + loc_item.item_name + ' is on backorder.'
break
}
//for each line set the "itemreceive" field to true
for (var i = 0; i < lineCount; i++) {
log.debug('i in lineCount: ', i)
var prod_id = fulfillment.getSublistValue({
sublistId: 'item',
fieldId: 'item',
line: i
})
log.debug('Item Name: ', prod_id)
fulfillment.selectLine({
sublistId: 'item',
line: i
});
// let items_location = loc_items.map(a => a.item_id);
var items_location = []
for (ll = 0; ll < loc_items.length; ll++) {
log.debug(ll + ': itemID: ' + loc_items[ll].item_id)
items_location.push(loc_items[ll].item_id)
}
if (!items_location.includes(prod_id)) {
continue;
}
log.debug('setting items to add')
fulfillment.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'itemreceive',
value: true
});
fulfillment.commitLine({
sublistId: 'item'
});
log.debug('commited')
} //looping through line items in the SO
} //loop of location items
var ful_id = fulfillment.save({ ignoreMandatoryFields: true })
Kevin
06/26/2022, 2:53 PMKevin
06/26/2022, 2:53 PMGail Kasnett
06/26/2022, 3:46 PMbattk
06/26/2022, 6:45 PMbattk
06/26/2022, 6:45 PMbattk
06/26/2022, 6:47 PMEric B
06/26/2022, 9:52 PMGail Kasnett
06/27/2022, 9:00 AM