Reserve and Unreserve salesline inventory in X++

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 SalesLine record.    /// The 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.

Omar Iqbal

Technical Consultant

References:

  1. https://dynamicsaxlk.wordpress.com/2013/04/05/reserve-quantity-by-x-code/
  2. http://sujanadynamics.blogspot.com/2016/03/auto-reserve-using-x-code.html
  3. https://axfactory.wordpress.com/2015/02/28/reserve-and-remove-reservation-for-an-item-x-ax2012/
  4. https://www.dynamicsuser.net/t/delete-physical-reservation-from-x/46502
  5. https://rahulmsdax.blogspot.com/2018/11/remove-reservations-and-markings-from.html
Total
0
Shares
13 comments
  1. 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)

  2. 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!

  3. 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

Comments are closed.

Previous Article

FinOps Business Event connection with Azure APIM - Azure Function

Next Article

Generate Picking List and its registration in X++

Related Posts