web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

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
I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,196 Super User 2025 Season 2 on at
    Hi Alex,

    Is it possible to manually reserve this batch number via the user interface?
  • Alex Nach Profile Picture
    32 on at
    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
    301,196 Super User 2025 Season 2 on at
    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
    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
  • Anton Venter Profile Picture
    20,346 Super User 2025 Season 2 on at
    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
    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
  • André Arnaud de Calavon Profile Picture
    301,196 Super User 2025 Season 2 on at
    Hi Alex,
     
    Glad to read you found the solution. Can you share the details so anyone can learn from this?

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 490 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 241 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans