Hi Experts,
I am facing an issue in D365 Finance & Operations (Supply Chain – Inventory Reservation) where the reservation behaves differently across forms. As I want to reserve inventory not from the Pack location (Which I put under parameter) while Creating BOM Journal from Reported as finished.
Current Behavior
I reserve inventory programmatically using InventUpd_Reservation.
Reservation shows correctly in:
InventTrans
BOM Reservation form
However, in InventOnhandItem, the reservation still appears against the PACK WMS location, even though:
I programmatically change the InventDimId to a different valid WMS location with stock.
So effectively:
InventTrans & BOM → show reservation from the correct location
InventOnhandItem → still shows reservation from PACK location (I dont want to reseve items from the Pack location
What I am trying to achieve
Yet InventSum (On-hand) still keeps the reservation under the old PACK dimension.
PACK location should NEVER hold reservation
Reservation should always move to another valid WMS location with available physical stock
All 3 places must be in sync:
InventTrans
BOM Reservation
InventOnhandItem
Below is the code snippet; Please help me guys
[ExtensionOf(tableStr(InventJournalTrans))]
internal final class ZInventJournalTrans_Extension
{
public void insert(NoYes _dropEstimated)
{
next insert(_dropEstimated);
InventJournalTable inventJournalTable = InventJournalTable::find(this.JournalId);
if(inventJournalTable.RecId)
{
InventTrans inventTrans;
InventTransOrigin inventTransOrigin;
InventMovement inventMovement;
InventUpd_Reservation inventUpd_Reservation ;
InventDim inventDim,inventDimJoin;
inventSum inventSum,inventSumVal ;
ZCustParameters zCustParameters = ZCustParameters::find();
str location;
container locationContainer;
real ActualAvailableQty;
int i ;
Microsoft.Dynamics.Ax.Xpp.ErrorException xppEx;
try
{
location = zCustParameters::find().wmsLocationId;
locationContainer = str2con(location,';');
//// Reserve an item
select inventTransOrigin
where inventTransOrigin.InventTransId == this.InventTransId
join inventTrans
where inventTrans.InventTransOrigin == inventTransOrigin.RecId
&& inventTrans.StatusReceipt == StatusReceipt::None ;
select sum(AvailPhysical) from inventSum
where inventSum.ItemId == this.ItemId
&& inventSum.InventLocationId == this.inventDim().InventLocationId;
//&& inventSum.wMSLocationId != 'Pack';
ActualAvailableQty = inventSum.AvailPhysical ;
for(i=1 ;i<=conLen(locationContainer);i++)
{
InventSum inventSumloc;
str wmslocationIdLoc;
wmslocationIdLoc = conPeek(locationContainer,i);
select sum(AvailPhysical) from inventSumloc
where inventSumloc.ItemId == this.ItemId
&& inventSumloc.InventLocationId == this.inventDim().InventLocationId
&& inventSumloc.wMSLocationId == wmslocationIdLoc;
//&& inventSumloc.wMSLocationId != 'Pack';
ActualAvailableQty -= inventSumloc.AvailPhysical ;
}
if (inventTrans.RecId )//&& ActualAvailableQty > 0)
{
if (conFind(locationContainer, inventDim::find(inventTrans.inventDimId).wMSLocationId) > 0) //|| inventDim::find(inventTrans.inventDimId).wMSLocationId == 'Pack')
{
inventTrans.selectForUpdate(true);
ttsbegin;
// Find new InventDim with stock >0 and not pack
select sum(AvailPhysical), InventDimId, wmsLocationId
from inventSumVal
group by inventSumVal.wMSLocationId, inventSumVal.inventDimId
where inventSumVal.ItemId == inventTrans.ItemId
&& inventSumVal.AvailPhysical > 0
//&& inventSumVal.wMSLocationId != 'Pack'
&& inventSumVal.InventDimId != inventTrans.InventDimId;
if (inventSumVal.InventDimId)
{
inventTrans.InventDimId = inventSumVal.InventDimId;
inventTrans.doUpdate();
}
ttscommit;
}
if (ActualAvailableQty < -inventTrans.Qty)
{
inventMovement = inventTrans.inventMovement(true);
inventUpd_Reservation = InventUpd_Reservation::newInventDim(
inventMovement,
inventTrans.inventDim(),
-ActualAvailableQty,
false);
inventUpd_Reservation.updateNow();
}
else
{
inventMovement = inventTrans.inventMovement(true);
inventUpd_Reservation = InventUpd_Reservation::newInventDim(
inventMovement,
inventTrans.inventDim(),
inventTrans.Qty,
false);
inventUpd_Reservation.updateNow();
}
}
}
catch (xppEx)
{
warning(strFmt("Error Occurred for Journal Id - %1 and Item id - %2", this.JournalId, this.ItemId));
warning(xppEx.Message);
}
catch (Exception::Deadlock)
{
warning(strFmt("Error Occurred for Journal Id - %1 and Item id - %2", this.JournalId, this.ItemId));
}
catch (Exception::Warning)
{
CLRInterop::getLastException();
}
catch (Exception::CLRError)
{
CLRInterop::getLastException();
}
}
}