Sunday, 29 March 2020

How to reserve, unreserve item from inventory using x++ code


Hi Viewers,

Today will see how to reserve/Un reserve an item from inventory.

If you want to reserve then pass negative Qty (-1 * Qty)

If you want to Un reserve then pass positive Qty (1 * Qty)


Below sample code is to reserve an item

this.ReserveItem(salesLine, -1 * Qty)

    /// <summary>
    ///     Reserve/Unreserve item
    /// </summary>
    /// <param name = "_salesLine">
    ///     The _salesLine table buffer
    /// </param>
    /// <param name = "_lineQty">
    ///     The _lineQty
    /// </param>
    public void ReserveItem(SalesLine  _salesLine, SalesQty  _lineQty)
    {
        InventUpd_Reservation       inventUpd_Reservation;
        inventMovement              movement;
        InventDim                   inventDimCriteria;
        InventDimParm               inventDimParm;

        movement            = InventMovement::construct(_salesLine);
        inventDimCriteria   = InventDim::find(_salesLine.inventDimId);
        inventDimParm       = movement.initDimParmAutoReserv(inventDimCriteria);

        // Product dimensions must be specified on movement and should be enforced - even when blank.
        inventDimParm.setAllProductDimensions();

        inventUpd_Reservation = InventUpd_Reservation::newMovement(movement, _lineQty, true);
        inventUpd_Reservation.parmInventDimFixed(InventDimFixedClass::inventDimParm2InventDimFixed(inventDimParm));
        inventUpd_Reservation.parmInventDimCriteria(inventDimCriteria);
        inventUpd_Reservation.parmInventDimParm(inventDimParm);
        inventUpd_Reservation.updateNow();
    }

No comments:

Post a Comment