Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Item tracking line lot number problem.

Posted on by 14
Hi all,
 
Could you please give some idea to solve the problem? I'm trying to post item journal line by code but, it keeps saying there is no lot number.
 
The problem is when I see the item tracking line, lot number is added. But when I press post in item reclassification journal, the error pop up. (also please help me to fix the quantity gets negative number :c)
 
LotNoInfo.Reset();
        LotNoInfo.CalcFields(Inventory);
        LotNoInfo.SetFilter(Inventory, '>0');
 
        if LotNoInfo.FindSet() then
            repeat
                LotNoInfo.CalcFields(Inventory);
 
                if ((LotNoInfo."Expire Date" <= TodayDate) or
                    (LotNoInfo."Retest Date" <= TodayDate)) and
                   (LotNoInfo.Inventory > 0) then begin
                    ItemLedgEntry.Reset();
                    ItemLedgEntry.SetRange("Item No.", LotNoInfo."Item No.");
                    ItemLedgEntry.SetRange("Lot No.", LotNoInfo."Lot No.");
                    ItemLedgEntry.SetFilter("Remaining Quantity", '>0');
 
                    if ItemLedgEntry.FindSet() then
                        repeat
                            WarehouseEntry.Reset();
                            WarehouseEntry.SetRange("Item No.", ItemLedgEntry."Item No.");
                            WarehouseEntry.SetRange("Lot No.", ItemLedgEntry."Lot No.");
                            WarehouseEntry.SetRange("Location Code", ItemLedgEntry."Location Code");
                            WarehouseEntry.SetRange("Reference No.", ItemLedgEntry."Document No.");
                            if WarehouseEntry.FindLast() and (WarehouseEntry."Bin Code" <> '') then begin
                                LineNo += 10000;
 
                                ItemReclassJournalLine.Init();
                                ItemReclassJournalLine."Entry Type" := ItemReclassJournalLine."Entry Type"::Transfer;
                                ItemReclassJournalLine."Journal Template Name" := ItemReclassJournalTemplate.Name;
                                ItemReclassJournalLine."Journal Batch Name" := ItemReclassJournalBatch.Name;
                                ItemReclassJournalLine."Line No." := LineNo;
                                ItemReclassJournalLine."Posting Date" := TodayDate;
                                ItemReclassJournalLine."Document No." := CurrentDocumentNo;
 
                                ItemReclassJournalLine.Validate("Item No.", LotNoInfo."Item No.");
                                ItemReclassJournalLine.Validate("Location Code", ItemLedgEntry."Location Code");
                                ItemReclassJournalLine.Validate("Variant Code", ItemLedgEntry."Variant Code");
                                ItemReclassJournalLine.Description := 'asdf';
 
                                Quantity := ABS(ItemLedgEntry."Remaining Quantity");
                                ItemReclassJournalLine.Validate(Quantity, Quantity);
 
                                ItemReclassJournalLine.Validate("New Location Code", 'asdf');
                                ItemReclassJournalLine.Validate("New Bin Code", 'asdf');
 
                                ItemReclassJournalLine.Validate("Lot No.", LotNoInfo."Lot No.");
                                ItemReclassJournalLine.Validate("New Lot No.", LotNoInfo."Lot No.");
 
                                ItemReclassJournalLine.Validate("Bin Code", WarehouseEntry."Bin Code");
                                ItemReclassJournalLine.Insert();
 
 
                                CreateReservationEntry(ItemReclassJournalLine, LotNoInfo."Lot No.", Quantity);
                            end;
                        until ItemLedgEntry.Next() = 0;
                end;
            until LotNoInfo.Next() = 0;
 
 
    end;
 
    local procedure CreateReservationEntry(ItemReclassJournalLine: Record "Item Journal Line"; LotNo: Code[50]; Quantity: Decimal)
    var
        ReservEntry: Record "Reservation Entry";
        EntryNo: Integer;
    begin
        Quantity := ABS(Quantity);
 
        EntryNo := 0;
        ReservEntry.Reset();
        if ReservEntry.FindLast() then
            EntryNo := ReservEntry."Entry No.";
        EntryNo += 1;
 
        ReservEntry.Init();
        ReservEntry."Entry No." := EntryNo;
        ReservEntry."Item No." := ItemReclassJournalLine."Item No.";
        ReservEntry."Location Code" := ItemReclassJournalLine."Location Code";
        ReservEntry."Quantity (Base)" := Quantity;
        ReservEntry."Reservation Status" := ReservEntry."Reservation Status"::Surplus;
        ReservEntry."Creation Date" := WorkDate();
        ReservEntry."Source Type" := DATABASE::"Item Journal Line";
        ReservEntry."Source Subtype" := ItemReclassJournalLine."Entry Type".AsInteger();
        ReservEntry."Source ID" := ItemReclassJournalLine."Journal Template Name";
        ReservEntry."Source Batch Name" := ItemReclassJournalLine."Journal Batch Name";
        ReservEntry."Source Ref. No." := ItemReclassJournalLine."Line No.";
        ReservEntry."Lot No." := LotNo;
        ReservEntry."New Lot No." := LotNo;
        ReservEntry.Validate("Item Tracking", ReservEntry."Item Tracking"::"Lot No.");
        ReservEntry."Qty. per Unit of Measure" := ItemReclassJournalLine."Qty. per Unit of Measure";
 
 
        ReservEntry.Positive := false;
 
        ReservEntry.Insert();
    end;
Categories:
  • Suggested answer
    Ramiz Profile Picture
    Ramiz 326 on at
    Item tracking line lot number problem.
    Hi,

    try these 2 codes.
     

    procedure CreateManualLotReservationEntry(var ItemJournalLine: Record "Item Journal Line"; LotNo: Code[50])
        var
            ReservationEntry: Record "Reservation Entry";
            ReservationManagement: Codeunit "Reservation Management";
        begin
            ReservationEntry.Init();
            ReservationEntry."Entry No." := ReservationEntry.GetLastEntryNo() + 1;
            ItemJournalLine.SetReservationEntry(ReservationEntry);
            ReservationEntry.Validate("Reservation Status", ReservationEntry."Reservation Status"::Surplus);
            ReservationEntry.Validate("Quantity (Base)", ItemJournalLine."Quantity (Base)");
            ReservationEntry.Validate("Lot No.", LotNo);
            ReservationEntry.Validate("Item Tracking", ReservationEntry."Item Tracking"::"Lot No.");
            ReservationEntry.Positive := (ReservationEntry."Quantity (Base)" > 0);
            ReservationEntry.Insert(true);
            ReservationManagement.SetReservSource(ItemJournalLine);
            ReservationManagement.SetItemTrackingHandling(1); // Allow Deletion
        end;
    procedure CreateLotReservationEntry(var ItemjournalLine: Record "Item Journal Line"; LotNo: Code[50])
        var
            Item: Record Item;
            TempReservationEntry: Record "Reservation Entry" temporary;
            ReservationEntry: Record "Reservation Entry";
            CreateReservEntry: Codeunit "Create Reserv. Entry";
        begin
            Item.Get(ItemjournalLine."Item No.");
    
            TempReservationEntry.Init();
            TempReservationEntry."Lot No." := LotNo;
    
            CreateReservEntry.CreateReservEntryFor(Database::"Item Journal Line", ItemjournalLine."Entry Type".AsInteger(), ItemjournalLine."Journal Template Name", ItemjournalLine."Journal Batch Name", 0,
                                                    ItemjournalLine."Line No.", 1, ItemjournalLine.Quantity, ItemjournalLine."Quantity (Base)", TempReservationEntry);
            CreateReservEntry.CreateEntry(ItemjournalLine."Item No.", ItemjournalLine."Variant Code", ItemjournalLine."Location Code", '', WorkDate(), WorkDate(), 0, Enum::"Reservation Status"::Surplus);
        end;
     
  • JC-10102114-0 Profile Picture
    JC-10102114-0 14 on at
    Item tracking line lot number problem.
    Hi ZHU
     
    Your webpage is always our the best reference. However, in this time the problem was not solved by your post. :c. When I tried to message to see the log, there is exactly lot number. BUT, the problem is when I press post button, in the codeunit 23 (Item Jnl.-Post Batch) clears the lot number as below code. Could you please give us more advise for this ;-;
    local procedure UpdateItemTracking(var ItemJournalLine: Record "Item Journal Line")
        var
            IsHandled: Boolean;
        begin
            IsHandled := false;
            OnBeforeUpdateItemTracking(ItemJournalLine, IsHandled);  <---- This 'IsHandled' is not triggered somehow
            if IsHandled then
                exit;
     
            if ItemJnlBatch."Item Tracking on Lines" then
                ItemJournalLine.CreateItemTrackingLines(false);
            ItemJournalLine.ClearTracking();
            ItemJournalLine.ClearDates();
        end;
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,565 Super User 2024 Season 2 on at
    Item tracking line lot number problem.
    I suggest you debug it to see if there is any value.
    And I have discussed similar requirements before, I hope I can give you some tips.
    Dynamics 365 Business Central: How to create Item Tracking Lines automatically during an inbound transaction (Customization)
     
    Thanks.
    ZHU

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans