erictgrubaugh
11/28/2017, 5:31 PMfunction updateItemCosting(scriptContext) {
var itemId = scriptContext.currentRecord.getValue ({fieldId: 'custrecord_custom_item_pricing_item'})
var itemRec = record.load({type: record.Type.ITEM, id: itemId});
var itemCost = calculateCost(itemRec);
scriptContext.currentRecord.setValue ({fieldId: 'custrecord_custom_item_pricing_item_cost', Value: itemCost});
}
function calculateCost(item) {
var itemAvailable = itemRec.getValue ({fieldId: 'available'});
var itemAvgCost = itemRec.getValue ({fieldId: 'averagecost'});
var itemLastPurchasePrice = itemRec.getValue ({fieldId: 'lastpurchaseprice'});
var itemPurchasePrice = itemRec.getValue ({fieldId: 'cost'});
return (((itemAvailable > 0) && (itemAvgCost || itemLastPurchasePrice)) || itemPurchasePrice);
}
If you don't like the style of the return
statement in calculateCost
, you could certainly just drop your if-else
structure in there