Hi Farokh,
I wrote the code for one of my client to update inventory dimension and delivery date for PO using doUpdate method when change management is activated. I used the dialog form to take input from user and then updated the PO with those values.
Below is the code:
public static void updateInventDimAndDeliveryDateForPO(
PurchTable _purchTable,
InventSiteId _inventSiteId,
InventLocationId _inventLocationId,
DlvDate _deliveryDate)
{
PurchLine purchLine;
InventDim inventDim;
InventTrans inventTrans;
InventTransOrigin inventTransOrigin;
ttsBegin;
if (_inventLocationId || _inventSiteId || _deliveryDate)
{
_purchTable.selectForUpdate(true);
_purchTable.InventLocationId = _inventLocationId ? _inventLocationId : _purchTable.InventLocationId;
_purchTable.InventSiteId = _inventSiteId ? _inventSiteId : _purchTable.InventSiteId;
_purchTable.DeliveryDate = _deliveryDate ? _deliveryDate : _purchTable.DeliveryDate;
// Update delivery address based on Site or Warehouse selected on the form.
_purchTable.setAddressFromInventSiteId(_inventSiteId);
_purchTable.setAddressFromInventLocationId(_inventLocationId);
_purchTable.doUpdate();
}
// Update all purchase order lines associated with this purchase order header.
while select forUpdate purchLine
where purchLine.PurchId == _purchTable.PurchId
{
if (_inventLocationId || _inventSiteId)
{
// Find the inventory storage dimension for purchase order line record.
inventDim = purchLine.inventDim();
inventTransOrigin = InventTransOrigin::findByInventTransId(purchLine.InventTransId);
// Find Inventory transaction record related to this purchase order with Status Ordered.
select forUpdate * from inventTrans
where inventTrans.InventTransOrigin == inventTransOrigin.RecId &&
inventTrans.inventDimId == purchLine.InventDimId &&
inventTrans.StatusReceipt == StatusReceipt::Ordered;
// Update the inventory dimensions with the new dimensions if specified in the dialog form.
inventDim.InventLocationId = _inventLocationId;
inventDim.InventSiteId = _inventSiteId;
// Find the inventory dimension Id based on the value specified on the drop dialog form.
inventDim = InventDim::findOrCreate(inventDim);
// If inventory transactions exist for this PO with status 'Ordered'.
if (inventTrans.RecId)
{
// Update purchase order line with new Inventory dimension Id.
purchLine.InventDimId = inventDim.inventDimId;
// Update the inventory transaction record with new inventory dimensions.
inventTrans.inventDimId = purchLine.InventDimId;
inventTrans.doUpdate();
}
}
if (_purchTable.DeliveryDate)
{
purchLine.DeliveryDate = _purchTable.DeliveryDate;
}
purchLine.doUpdate();
}
ttsCommit;
}
Please let me know if you have further queries.
Thanks,
Baber.