This post is machine-translated. The original post in german language can be found here.

Reserve/Unreserve a sales order line

The are a lot of examples about how to reserve a sales order line. But i did not find an example, where the result of the reservation has been tested.

So i had to write some code for my own. I am checking the reserved value before executing my code, and afterwards. If the reserved quantity is still the same, my job seems to have failed.

static void reserveSalesLine(Args _args)
{
    InventTransIdSumSingleStatus inventTransIdSumSingleStatus;
    SalesLine salesLine;
    InventMovement inventMovement;
    InventDim inventDim;
    InventDimParm inventDimParmCriteria;
    InventQtyReservPhysical oldReservedQty;
    InventQtyReservPhysical newReservedQty;
    InventUpd_Reservation inventUpd_Reservation;
    InventQty reserveQty;

    // Inline method to get current reserved quantity for specific inventDim
    InventQtyReservPhysical getReservedQty()
    {
        inventDimParmCriteria.initFromInventDim(inventDim);        

        inventTransIdSumSingleStatus = InventTransIdSumSingleStatus::newTransOriginIdStatus(InventTransOriginSalesLine::findInventTransOriginId(salesLine.DataAreaId, salesLine.InventTransId),
                                                                                            StatusReceipt::None,
                                                                                            StatusIssue::ReservPhysical);
        inventTransIdSumSingleStatus.parmInventDimCriteria(inventDim);
        inventTransIdSumSingleStatus.parmInventDimParmCriteria(inventDimParmCriteria);

        return inventTransIdSumSingleStatus.reservPhysical();
    }

    // Sales order line
    salesLine = SalesLine::findInventTransId('012431');
    inventMovement = InventTrans::findTransId(salesLine.InventTransId).inventMovement(true);

    // Build inventDim-Record, where the quantity should be reserved
    inventDim.clear();
    inventDim.InventSiteId      = "1";
    inventDim.InventLocationId  = "12";
    inventDim.wmsLocationId     = "12";
    inventDim = InventDim::findOrCreate(inventDim);

    // Get current physical reserved Quantity
    oldReservedQty = getReservedQty();

    // Set quanity which should be reserved (negative values to reserve, postive value to unreserve)
    reserveQty = -2;

    inventUpd_Reservation = InventUpd_Reservation::newInventDim(inventMovement,
                                                                inventDim,
                                                                reserveQty,
                                                                true);
    inventUpd_Reservation.updateNow();

    // Get new reserved quantity
    newReservedQty = getReservedQty();

    // Compare old and new reserved quantity to identify if reservation failed
    if(oldReservedQty == newReservedQty)
    {
        error("Reservation failed.");
    }
}
These post applies to following version:
Dynamics AX 2012

Lewis Batcher 11/10/2016 00:31 | #1

Thank you. I was able to get unreserved and then reserve working.

Guest 12/01/2016 23:02 | #2

Very helpful piece of code, thank you.

Francisco 03/19/2021 04:10 | #3

Muchas gracias, resolviste mi problema

Peter 10/18/2021 10:59 | #4

Thanks for your code

Peter 10/18/2021 10:59 | #5

Thanks for your code

Piyush 05/18/2023 08:03 | #6

How can i use it in Custom service integration in D365 FO

Piyush 05/19/2023 06:23 | #7


SXascasc 10/25/2023 12:27 | #8

!@#$%^&*(!@$%^&*()_~!@#$%^&*()_+}{:"?>

SXascasc 10/25/2023 12:30 | #9

!@#$%^&*(!@$%^&*()_~!@#$%^&*()_+}{:"?>

Right Left 10/25/2023 12:31 | #10

!@#$%^&*(!@$%^&*()_~!@#$%^&*()_+}{:"?> '''''''':;:s"'s;s;s;" ????

textfield,   or &#160



"Testing" etc...

Add comment
 
 

 

 
 
 
Posts of the actual month
März 2024
MoTuWeThFrSaSu
 123
45678910
11121314151617
18192021222324
25262728293031
 
© 2006-2024 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.