In this article we are looking into how to reserve inventory of SalesLine with batch and without batch, it also focuses on unreserve of inventory in X++.
Reserve partial inventory quantity of sales line with Batch number
Use this given method below to reserve partial inventory quantity with batch number for a sales line in X++
/// This method reserves SalesLine record with specific InventBatchId. ///The SalesLine record to reserve. ///Quantity to reserve. ///InventBatchId to reserve against public void reservesalesLineByBatchId(SalesLine _salesLine,
InventQty _reserveQuantity,
InventBatchId _inventBatchId) { InventUpd_Reservation reservation; InventMovement movement;
InventDim inventDimSalesLine, inventDim;
movement = InventMovement::construct(_salesLine); if (_reserveQuantity > 0) { inventDimSalesLine = InventDim::find(_salesLine.InventDimId); inventDim.clear(); inventDim.data(inventDimSalesLine); inventDim.InventBatchId = _inventBatchId;
inventDim = InventDim::findOrCreate(inventDim); reservation = InventUpd_Reservation::newInventDim(movement,
inventDim,
-_reserveQuantity,
false); reservation.updateNow(); } }
Reserve inventory on sales line completely
Use this given method below to reserve inventory completely for a sales line in X++
/// This method reserves SalesLine record. ///The SalesLine record to reserve. public void reserveInventory(SalesLine _salesLine) { InventUpd_Reservation reservation; InventMovement movement;
movement = InventMovement::construct(_salesLine); real x = abs(movement.transIdSum().reserved()); InventQty reserveQuantity = _salesLine.QtyOrdered - x; if (reserveQuantity > 0) { reservation = InventUpd_Reservation::newMovement( movement, -reserveQuantity, true); reservation.updateNow(); } }
Unreserve inventory on sales line completely
Use this given method below to unreserve inventory completely for a sales line in X++
/// This method unreserves /// TheSalesLine record.SalesLine record to unreserve. public void unReserveInventory(SalesLine _salesLine) { InventTrans inventTrans; InventTransOrigin inventTransOrigin; InventMovement inventMovement; InventUpd_Reservation inventUpd_Reservation; SalesLine salesLine; // 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.RecId == _salesLine.RecId { 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(); } } }
Thank you for reading this article hope you find it useful.
Technical Consultant
References:
- https://dynamicsaxlk.wordpress.com/2013/04/05/reserve-quantity-by-x-code/
- http://sujanadynamics.blogspot.com/2016/03/auto-reserve-using-x-code.html
- https://axfactory.wordpress.com/2015/02/28/reserve-and-remove-reservation-for-an-item-x-ax2012/
- https://www.dynamicsuser.net/t/delete-physical-reservation-from-x/46502
- https://rahulmsdax.blogspot.com/2018/11/remove-reservations-and-markings-from.html
Omar, thanks for the code samples, they are very useful. Just one note, for the third example, in my opinion the second IF statement is totally useless, since you are selecting the condition on the while select statement.
if (inventTrans.StatusIssue == StatusIssue::ReservPhysical ||
inventTrans.StatusIssue == StatusIssue::ReservOrdered)
I would like to thank you for the efforts you have put in penning this blog. I really hope to see the same high-grade blog posts by you in the future as well. In truth, your creative writing abilities has encouraged me to get my own website now đ
ItĂs nearly impossible to find well-informed people for this topic, but you seem like you know what youĂre talking about! Thanks
Thanks-a-mundo for the article.Much thanks again. Much obliged.
This is a really good tip particularly to those fresh to the blogosphere. Brief but very accurate information… Many thanks for sharing this one. A must read article!
I was looking through some of your content on this internet site and I conceive this site is really instructive! Keep on posting.
When you think of universities you would like to attend, make a highlight reel for each one you consider.
Hey, thanks for the article.Really looking forward to read more. Keep writing.
There’s certainly a great deal to learn about this subject. I really like all the points you’ve made.
Hi there! Would you mind if I share your blog with my zynga group? There’s a lot of folks that I think would really enjoy your content. Please let me know. Thanks
Im obliged for the article.Really looking forward to read more. Great.
A big thank you for your blog article.Really looking forward to read more. Cool.
I really liked your post.Thanks Again. Will read on…