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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Reservation sequence from AL code

(3) ShareShare
ReportReport
Posted on by 10

Hi,

In a Production application, in case we want to create a Reservation (for a SalesLine as an example) with Lots or S/N, I am trying to AL code the logic to perform this Auto Reservation, but in vain.

Below I my current code that is failing. I have been trying many different approaches but I simply cannot.

       var ReservMgt: Codeunit "Reservation Managment"
 
        ReservEntry.Init();
        ReservEntry."Item No." := MatReq."Item No.";
        ReservEntry."Location Code" := MatReq."Location Code";
        // populate as many fields as possible ......
       
        ReservMgt.SetExternalDocumentResEntry(ReservEntry, false);
        ReservMgt.AutoReserveOneLine(1, QtyToReserve, QtyToReserve, MatReq.Description, DT2Date(MatReq."Requested Delivery Date"));
 
I have also tried the ReservMgt.AutoReserve(), but it does not work.
 
I suspect that the ItemTracking shall be specified before. Not sure.


 
Reservation Entries.png
Reservation_AutoReserve.png
I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    101,995 Super User 2026 Season 1 on at
    Hi, hope the following can give you some hints.
     
    Thanks.
    ZHU
  • Suggested answer
    OussamaSabbouh Profile Picture
    17,586 Super User 2026 Season 1 on at
    Hello,
    For lot/SN items, don’t try to build Reservation Entry manually and then call Reservation Management directly; that usually fails because reservation + item tracking is not just one record, it is a linked reservation structure, and for item tracking Business Central stores active tracking/reservation data through table 337 and Tracking Specification. The safest approach is to imitate the standard page/action flow for the real source line: first create/assign the required item tracking lot/SN for the demand line, then call the relevant source reservation logic, for example the Sales Line reservation codeunit/page flow for a Sales Line, or Production Component reservation flow for a component line. AutoReserve can create a non-specific reservation, but if you need a specific lot/SN, the lot/SN must be part of the tracking/reservation flow, not only filled in a temporary ReservEntry. So I would debug the standard Auto Reserve action from the Reservation page and reuse the same source-specific code path instead of calling SetExternalDocumentResEntry() manually.
    Regards,
    Oussama Sabbouh
  • RL-03061843-0 Profile Picture
    10 on at
    Thanks and I will try it asap and then confirm.
     
    Meanwhile, you solutions imply that Lots must be manually selected. But considering a FIFO inventory method, would there be procedures handling the FIFO (sorting by reception date, picking Lot by Lot to fulfill the required quantity) ? Ok it's not a big deal to mimic this behavior when building the temporary Reservation entries, but I always prefer using standard procedures.

    thanks 
  • Suggested answer
    Grigorios Mavrogeorgis Profile Picture
    2,510 Super User 2026 Season 1 on at
    Hi,
    one thing jumping out is the AutoReserveOneLine(1, ...). That first parameter is not the document line, is the reservation summary entry number, the supply bucket from the summary. So passing 1 by hand you are telling it reserve from some entry that is probably not your lot ILE at all. That alone can make it do nothing.
    I would drop AutoReserveOneLine here. Set the source first with SetReservSource on your SalesLine, then call AutoReserve and let it walk all the summary lines itself. The SetExternalDocumentResEntry is not really for this case I think. AutoReserveOneLine you only use when you already read the summary and know which entry no to hit.

    For the lot/serial, auto reserve does not pick a lot for you. It reserve against available qty from the ILE, follows the tracking if supply is already lot specific, otherwise you must specify item tracking on the line first like you suspect.
    Which version and which source, Sales Line? The calls shifted across versions.
     
    Hope this help. Best regards.
    ✅ Tick the checkbox below to mark the answer as verified, if it helped resolve your question.
     
    Regards
    Gregory Mavrogeorgis
     

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,222 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,603 Super User 2026 Season 1

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 1,186 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans