Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Sales line reservation

(1) ShareShare
ReportReport
Posted on by 32
Hello friends.
 
Can anyone point me in the right direction on how to reserve a SalesLine item with a specific batch? I've tried numerous approaches but haven't been successful.
Here's my original example that works fine without specifying a batch. The reservation of batch is automatic, I assume FIFO is applied, and it picks up batch 1 out of the 5 available.
select inventTrans
                where  inventTrans.ItemId                   == _salesLine.ItemId
                    &&  inventTrans.StatusReceipt           == StatusReceipt::None
                        &&  inventTrans.StatusIssue         == StatusIssue::OnOrder
                exists join inventTransOrigin
                    where inventTransOrigin.RecId           == inventTrans.InventTransOrigin
                        && inventTransOrigin.InventTransId  == _salesLine.InventTransId;

inventmovement = inventTrans.inventmovement(true);
inventUpd_Reservation = InventUpd_Reservation::newInventDim(inventmovement, inventTrans.inventDim(), inventTrans.Qty, false);
inventUpd_Reservation.updatenow();
What I'm trying to achieve is to specifically reserve batch #3. I found some examples online, but none of them seem to work for me.
One, in particular, suggests copying inventDim and creating a new one this way (see below) but that doesn't work.
inventBatchId = "123456BATCH";

inventDim.clear();
inventDim.data(InventDim::find(_salesLine.InventDimId));
inventDim.InventBatchId = InventBatch::find(inventBatchId, _salesLine.ItemId).inventBatchId;
inventDim = InventDim::findOrCreate(inventDim);

inventMovement = InventTrans::findTransId(_salesLine.InventTransId).inventMovement(true);
inventUpd_Reservation = InventUpd_Reservation::newInventDim(inventmovement, inventDim, inventTrans.Qty, false);
inventUpd_Reservation.updatenow();
The result is I don't see reservation made in D365FO or SQL (working in onebox). Originally, I followed this article https://axfactory.wordpress.com/2015/02/28/reserve-and-remove-reservation-for-an-item-x-ax2012/ to reserve/unreserve sales line. 
By the way, unreserve works just fine.

Any suggestions are appreciated as always. 
Thank you, Alex
  • André Arnaud de Calavon Profile Picture
    295,254 Super User 2025 Season 1 on at
    Sales line reservation
    Hi Alex,
     
    Glad to read you found the solution. Can you share the details so anyone can learn from this?
  • Alex Nach Profile Picture
    32 on at
    Sales line reservation
    Hi Anton.
     
    That is not the case. The transaction table (InventTrans) doesn't store the Batch ID; it's stored in the InventDim table. Since D365 doesn't allow update (or create) to the InventDim table, the code I provided uses the FindOrCreate method to create a new InventDim entry. I eventually figured it out and was able to correctly force the Batch ID reservation.
     
    Thank you, Alex
  • Anton Venter Profile Picture
    19,957 Super User 2025 Season 1 on at
    Sales line reservation
    Hello Alex,
     
    I'm not able to test this at the moment, I guess it's not finding the transaction because you have to update the inventory transaction with the batch ID before calling the reservation code.
  • Alex Nach Profile Picture
    32 on at
    Sales line reservation
    Hi Andre,
     
    Yes, I did. It's baffling that no errors are thrown, yet the operation didn't produce results. My guess is that it's not failing, but rather can't find something (most likely the code I wrote based on what I could find is wrong and missing components), resulting in no action being taken. I made the unreserve function work right away, but I've been struggling with the reservation, specifically for the batch, for a couple of days now. I'm digging deeper into reservations, and if I make it work, I'll update here. In the meantime, if you or anyone else has experience with this, it would speed up the process.
     
    Thank you,
    Alex
  • André Arnaud de Calavon Profile Picture
    295,254 Super User 2025 Season 1 on at
    Sales line reservation
    Hi Alex,

    Have you used the debugger to find out if your coding is called and executed correctly?
  • Alex Nach Profile Picture
    32 on at
    Sales line reservation
    Hi Andre,
     
    Yes, absolutely. That batch exists in the system and has available quantities. I'm trying to asses work around EDI problem where sometimes we ship the wrong batch and not what's on the sales order :-).
    Need to find a way to unreserve original batch and reserve a new one.
     
    Thanks, Nach
  • André Arnaud de Calavon Profile Picture
    295,254 Super User 2025 Season 1 on at
    Sales line reservation
    Hi Alex,

    Is it possible to manually reserve this batch number via the user interface?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Product updates

Dynamics 365 release plans