D365 Business Central : How to Create Reservation Entry in AL
If you need to insert reservation, SN, or Lot No to your document, you will need to insert the record to Reservation Entry table. To do that, you can make use of Codeunit 99000830 “Create Reserv. Entry”.
Why are we not using Tracking Specification table ? Because BC is using Reservation Entry table to fill in the Tracking Specification table temporarily. That is why we need to fill in the Reservation Entry table, and not the Tracking Specification table.
First, you will need to create a Temporary Reservation Entry to store your Lot / Serial Number. You can create multiple temporary records if you have more than one serial or lot numbers.
TempReservEntry: Record "Reservation Entry" temporary;
TempReservEntry.Init();
TempReservEntry."Entry No." := 1;
TempReservEntry."Lot No." := 'ABC'; //use Serial No. for SN
TempReservEntry.Quantity := 1;
TempReservEntry."Expiration Date := Today();
TempReservEntry.Insert();
Once you have all the Temporary Reservation ready, you can start using Codeunit “Create Reserv. Entry”.
For Sales Line, you can use the following code.
var
TempReservEntry: Record "Reservation Entry" temporary;
SalesLine: Record "Sales Line"
CreateReservEntry: Codeunit "Create Reserv. Entry";
ReservStatus: Enum "Reservation Status";
with SalesLine do begin
if TempReservEntry.FindSet() then
repeat
CreateReservEntry.SetDates(0D, TempReservEntry."Expiration Date");
CreateReservEntry.CreateReservEntryFor(
Database::"Sales Line", "Document Type",
"Document No.", '', 0, "Line No.", "Qty. per Unit of Measure",
TempReservEntry.Quantity, TempReservEntry.Quantity * "Qty. per Unit of Measure", TempReservEntry);
CreateReservEntry.CreateEntry(
"No.", "Variant Code", "Location Code", '', 0D, 0D, 0, ReservStatus::Surplus);
until TempReservEntry.Next() = 0;
end;
For Purchase Line.
var
TempReservEntry: Record "Reservation Entry" temporary;
PurchLine: Record "Purchase Line";
CreateReservEntry: Codeunit "Create Reserv. Entry";
ReservStatus: Enum "Reservation Status";
with PurchLine do begin
if TempReservEntry.FindSet() then
repeat
CreateReservEntry.SetDates(0D, TempReservEntry."Expiration Date");
CreateReservEntry.CreateReservEntryFor(
Database::"Purchase Line", "Document Type",
"Document No.", '', 0, "Line No.", "Qty. per Unit of Measure",
TempReservEntry.Quantity, TempReservEntry.Quantity * "Qty. per Unit of Measure", TempReservEntry);
CreateReservEntry.CreateEntry(
"No.", "Variant Code", "Location Code", '', "Expected Receipt Date", 0D, 0, ReservStatus::Surplus);
until TempReservEntry.Next() = 0;
end;
For Transfer Order, you will need the Item Tracking Management as well.
var
TempReservEntry: Record "Reservation Entry" temporary;
TransLine: Record "Transfer Line";
CreateReservEntry: Codeunit "Create Reserv. Entry";
ItemTrackingMgt: Codeunit "Item Tracking Management";
ReservStatus: Enum "Reservation Status";
CurrentSourceRowID: Text[250];
SecondSourceRowID: Text[250];
with TransLine do begin
if TempReservEntry.FindSet() then
repeat
CreateReservEntry.SetDates(0D, TempReservEntry."Expiration Date");
CreateReservEntry.CreateReservEntryFor(
Database::"Transfer Line", 0,
"Document No.", '', "Derived From Line No.", "Line No.", "Qty. per Unit of Measure",
TempReservEntry.Quantity, TempReservEntry.Quantity * "Qty. per Unit of Measure", TempReservEntry);
CreateReservEntry.CreateEntry(
"Item No.", "Variant Code", "Transfer-from Code", '', "Receipt Date", 0D, 0, ReservStatus::Surplus);
CurrentSourceRowID := ItemTrackingMgt.ComposeRowID(5741, 0, "Document No.", '', 0, "Line No.");
SecondSourceRowID := ItemTrackingMgt.ComposeRowID(5741, 1, "Document No.", '', 0, "Line No.");
ItemTrackingMgt.SynchronizeItemTracking(CurrentSourceRowID, SecondSourceRowID, '');
until TempReservEntry.Next() = 0;
end;
For Item Journals, it is a bit tricky because depending on the journal type, you can get different result. So use with precaution.
var
TempReservEntry: Record "Reservation Entry" temporary;
ItemJrlLine: Record "Item Journal Line"
CreateReservEntry: Codeunit "Create Reserv. Entry";
ReservStatus: Enum "Reservation Status";
with ItemJrlLine do begin
if TempReservEntry.FindSet() then
repeat
CreateReservEntry.SetDates(0D, TempReservEntry."Expiration Date");
If "Entry Type" = "Entry Type"::Transfer then //movement
CreateReservEntry.SetNewSerialLotNo(TempReservEntry."Serial No.", TempReservEntry."Lot No.");
CreateReservEntry.CreateReservEntryFor(
Database::"Item Journal Line", "Entry Type",
"Journal Template Name", "Journal Batch Name", 0, "Line No.", "Qty. per Unit of Measure",
TempReservEntry.Quantity, TempReservEntry.Quantity * "Qty. per Unit of Measure", TempReservEntry);
CreateReservEntry.CreateEntry(
"Item No.", "Variant Code", "Location Code", '', 0D, 0D, 0, ReservStatus::Surplus);
until TempReservEntry.Next() = 0;
end;
Thanks!! Never know there is specific procedure to use.
This seems exactly what I need in order to be able to print serial numbers to order document. Though I am wondering where I should put the “Temporary Reservation Entry” creation code shown in the first picture with code in it.
You should put it before you find the Temporary Reservation Entry records.
if TempReservEntry.FindSet() then
I see. I suppose Reservation Entry table is also where both parts should be put with table extensions?
i want to assign multiples lot to the sales line through in business central
I have Sales Order Lines that I need to create reservations for. These will need to be either be specific lot/serial against Item Ledger Entries OR from specific Purchase Order lines. It’s not clear how to specify …
I need to “Create Reservations For” (a Sales Line) “From/against” (an existing Item Ledger Entry with Lot/Serial or a Purchase Line).
Can we assume that when the Purchase Line has been received that a corresponding Sales Line will be populated with the Item Tracking lines automatically? Or is there another step for this?
Id like to know this as this as well. @TonH were you able to resolve this?
I want to create reservations for all the sales lines on the sales order page automatically through an action button for all the items on the basis of Location and Bin code.