Below is the code where we can unreserve the inventory from sales orders/sales order lines.
Paste the below in a JOB
Static void Tutorial_UnreserveSalesTable(Args _args)
{
InventTrans inventTrans;
InventTransOrigin inventTransOrigin;
SalesLine salesLine;
InventMovement inventMovement;
InventUpd_Reservation inventUpd_Reservation ;
SalesId SalesId = "001260";//<--- Send/get sales id here
// Remove reservations and markings on a reserved salesorder
while select inventTrans
where inventTrans.StatusReceipt == StatusReceipt::None
&& (inventTrans.StatusIssue == StatusIssue::ReservPhysical
|| inventTrans.StatusIssue == StatusIssue::ReservOrdered)
exists join inventTransOrigin
where inventTransOrigin.RecId == inventTrans.InventTransOrigin
exists join salesLine
where salesLine.InventTransId == inventTransOrigin.InventTransId
&& SalesLine.SalesId == SalesId
{
if (inventTrans.MarkingRefInventTransOrigin)
{
InventTransOrigin::deleteMarking(inventTrans.MarkingRefInventTransOrigin, inventTrans.InventTransOrigin, -inventTrans.Qty, true);
InventTransOrigin::deleteMarking(inventTrans.InventTransOrigin, inventTrans.MarkingRefInventTransOrigin, inventTrans.Qty, true);
}
if (inventTrans.StatusIssue == StatusIssue::ReservPhysical || inventTrans.StatusIssue == StatusIssue::ReservOrdered)
{
Inventmovement = inventTrans.inventmovement(true);
inventUpd_Reservation = InventUpd_Reservation::newInventDim(inventmovement,inventTrans.inventDim(), -1 * inventTrans.Qty, false);
inventUpd_Reservation.updatenow();
}
}
}
@Rahul
Great! Thanks. I will use this as base for my newly to be created batchjob.
ReplyDeleteYou're welcome!
Delete