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
omar_iqbal

Recent Posts

Donation

2 months ago

Create and Update Rows Using a Plugin in Microsoft Dynamics CE (CRM)

Microsoft Dynamics CRM is a powerful Customer Relationship Management (CRM) tool that helps businesses manage…

10 months ago

Assign record owner to specific Team using Power Automate flow in Microsoft Dynamics CE (CRM)

Today we will be going over the steps how to assign owner to specific Team…

10 months ago

Set lookup in Microsoft Dynamics CE (CRM) using JavaScript

Today we will be going over the steps how to set the value of a…

10 months ago

Create and post free text invoice using X++ code

In this article we will see how we can create and post free text invoice…

2 years ago

Sales order confirmation using X++ code

In this article we will be focusing on confirmation of a sales order using X++…

2 years ago