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 :
Small and medium business | Business Central, N...
Suggested Answer

Create XML Port to import Item Journal in NAV 2018

(0) ShareShare
ReportReport
Posted on by 150

Hello Experts,

I have created a XMLPort to import Item journal line which includes LOT No. as well. Everything working fine except LOT No. While import CSV file it didn't bring LOT no.

can anyone please suggest/help.

Appreciate your help.

Regards,

Nia

I have the same question (0)
  • Suggested answer
    Marco Mels Profile Picture
    on at

    Hello,

    Maybe you can post the XMLport so others can take a look.

    Thanks.

  • Nia Profile Picture
    150 on at

    Sure Marco. Here My XML port :

    xmlport 50031 " Item Journal Import"

    {

       Direction = Import;

       FieldDelimiter = '"';

       FieldSeparator = ',';

       Format = VariableText;

       UseRequestPage = false;

       schema

       {

           textelement(Root)

           {

               tableelement(Integer; Integer)

               {

                   SourceTableView = sorting (Number);

                   AutoReplace = false;

                   AutoSave = false;

                   AutoUpdate = false;

                   XmlName = 'ItemJurnalImport';

                   textelement(PostingDate)

                   {

                   }

                   textelement(EntryType)

                   {

                   }

                   textelement(DocumentNo)

                   {

                   }

                   textelement(ItemNo)

                   {

                   }

                   textelement(LocationCodeIn)

                   {

                   }

                   textelement(LotNo)

                   {

                   }

                   textelement(QuantityIn)

                   {

                   }

                   textelement(UnitOfMeasure)

                   {

                   }

                   textelement(ExternalDocNo)

                   {

                   }

                   textelement(MachineCode)

                   {

                   }

                   textelement(PlantCode)

                   {

                   }

                   trigger OnBeforeInsertRecord();

                   begin

                       if LineNo > 0 then

                           InsertRecord();

                       LineNo := LineNo + 1;

                   end;

               }

           }

       }

       requestpage

       {

       }

       trigger OnInitXmlPort();

       var

           ItemJournalLine: Record "Item Journal Line";

       begin

           ItemJournalLine.setrange("Journal Template Name", JournalTemplateName);

           ItemJournalLine.SetRange("Journal Batch Name", JournalBatchName);

           if ItemJournalLine.FindLast then

               LineNo := ItemJournalLine."Line No."

           else

               LineNo := 0;

       end;

       local procedure InsertRecord();

       var

           ItemJnlLine: Record "Item Journal Line";

           Item: Record Item;

           ItemLotErr: TextConst ENU = 'Item %1 not found';

           Lot: Record "Lot No. Information";

           ItemNoLot: Code[20];

           LocationCode: Code[20];

           BinCode: Code[20];

           ItemNoMismatchErr: TextConst ENU = 'Item No. of Lot %1 does not match Item No. in file %2';

           NoItemNoErr: TextConst ENU = 'No Item No. specified in file';

           MachineCodeCode: Code[20];

           PlantCodeErr : Label 'Plant Code must not be blank.';

       begin

           IF PlantCode = '' then

               error(PlantCodeErr);

           if LotNo <> '' then

               GetLotInformation(LotNo, ItemNoLot, LocationCode, BinCode);

           ItemJnlLine.init;

           ItemJnlLine."Journal Template Name" := JournalTemplateName;

           ItemJnlLine."Journal Batch Name" := JournalBatchName;

           ItemJnlLine."Line No." := LineNo;

           Evaluate(ItemJnlLine."Posting Date", PostingDate);

           ItemJnlLine.validate("Posting Date");

           Evaluate(ItemJnlLine."Entry Type", EntryType);

           ItemJnlLine.validate("Entry Type");

           ItemJnlLine."Document No." := DocumentNo;

           if(ItemNo <> '') and(ItemNoLot <> '') and(ItemNo <> ItemNoLot) then

               error(ItemNoMismatchErr, ItemNoLot, ItemNo);

           if ItemNoLot <> '' then

               ItemJnlLine.Validate("Item No.", itemnolot)

           else if itemno <> '' then

                   ItemJnlLine.Validate("Item No.", ItemNo)

               else

                   error(NoItemNoErr);

           if LocationCode <> '' then

               ItemJnlLine.Validate("Location Code", LocationCode)

           else

               ItemJnlLine.Validate("Location Code",LocationCodeIn);

           if BinCode <> '' then

               ItemJnlLine.validate("Bin Code", BinCode);

           if UnitOfMeasure <> '' then

               ItemJnlLine.Validate("Unit of Measure Code", UnitOfMeasure);

           evaluate(ItemJnlLine.Quantity, QuantityIn);

           ItemJnlLine.Validate(Quantity);

           if lotno <> '' then

               CreateReservationEntry(ItemJnlLine,LotNo);

           if ExternalDocNo <> '' then

               ItemJnlLine.Validate("External Document No.", ExternalDocNo);

           MachineCodeCode := MachineCode;

           if MachineCodeCode <> '' then

               ItemJnlLine.ValidateShortcutDimCode(4, MachineCodeCode);

           IF PlantCode <> '' then

               ItemJnlLine.VALIDATE("Shortcut Dimension 2 Code",PlantCode);

           ItemJnlLine.insert;

       end;

       local procedure GetLotInformation(LotNo: Code[10]; var ItemNoLot: Code[20]; var LocationCode: Code[20]; var BinCode: Code[20]);

       var

           ItemLedgerEntry: Record "Item Ledger Entry";

           BinContent: Record "Bin Content";

           NoOpenLotErr: TextConst ENU = 'No open Item Ledger Entry for Lot No. %1';

       begin

           ItemLedgerEntry.SetRange("Lot No.", LotNo);

           ItemLedgerEntry.SetRange(Open, true);

           if not ItemLedgerEntry.FindFirst then

               error(NoOpenLotErr, LotNo);

           BinContent.setrange("Location Code", ItemLedgerEntry."Location Code");

           BinContent.setrange("Item No.", ItemLedgerEntry."Item No.");

           BinContent.SetRange(Default, true);

           if BinContent.FindFirst then

               BinCode := BinContent."Bin Code";

           ItemNoLot := ItemLedgerEntry."Item No.";

           LocationCode := ItemLedgerEntry."Location Code";

       end;

       local procedure CreateReservationEntry(PItemJnlLine: Record "Item Journal Line";LotNo:Code[20]);

       var

          ReservationEntry: Record "Reservation Entry";

           ResEntryNo: Integer;

       begin

           ReservationEntry.FindLast;

           ResEntryNo := ReservationEntry."Entry No.";

           ResEntryNo := ResEntryNo + 1;

           ReservationEntry.Init;

           ReservationEntry."Entry No." := ResEntryNo;

           ReservationEntry."Item No." := PItemJnlLine."Item No.";

           ReservationEntry."Location Code" := PItemJnlLine."Location Code";

           ReservationEntry.validate("Quantity (Base)",PItemJnlLine."Quantity (Base)" * -1);

           ReservationEntry."Reservation Status" := ReservationEntry."Reservation Status"::Prospect;

           ReservationEntry."Creation Date" := Today;

           ReservationEntry."Source Type" := Database::"Item Journal Line";

           ReservationEntry."Source Subtype" := 3;

           ReservationEntry."Source ID" := PItemJnlLine."Journal Template Name";

           ReservationEntry."Source Batch Name" := PItemJnlLine."Journal Batch Name";

           ReservationEntry."Source Ref. No." := PItemJnlLine."Line No.";

           ReservationEntry."Shipment Date" := PItemJnlLine."Posting Date";

           ReservationEntry."Created By" := UserId;

           ReservationEntry."Qty. per Unit of Measure" := PItemJnlLine."Qty. per Unit of Measure";

           ReservationEntry."Lot No." := LotNo;

           ReservationEntry."Item Tracking" := ReservationEntry."Item Tracking"::"Lot No.";

           ReservationEntry.Insert;

       end;

       procedure SetJournal(PItemJnlLine: Record "Item Journal Line");

       begin

           JournalTemplateName := PItemJnlLine."Journal Template Name";

           JournalBatchName := PItemJnlLine."Journal Batch Name";

       end;

       var

           LineNo: Integer;

           EntryNo: Integer;

           JournalTemplateName: Code[10];

           JournalBatchName: Code[10];

    }

  • Nia Profile Picture
    150 on at

    Any help will be really appreciated

  • Suggested answer
    Marco Mels Profile Picture
    on at

    Hello,

    Let me ask around internally if someone has an answer. Usually we do not do development type of support.

    Thanks.

  • Lars Lohndorf-Larsen Profile Picture
    on at

    Hi Nia,

    Thanks for providing the xml port. I can see that "Lot No." gets handled by al code, so it would need some debugging to find out why that code does not do what it's supposed to do. I would add MESSAGE in the xml port to see into the process, for example here:

    MESSAGE(LotNo); // add MESSAGE

    if LotNo <> '' then

    Or of course if you prefer, set breakpoints and debug the whole process.

    Sorry it's hard to say more, as the behaviour will depend a lot on the data you import, on your inventory setup and data.

  • Suggested answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    You can add Lot No. by creating reservation entries like below.

    local procedure CreateLotTracking(ItemJnl: Record "Item Journal Line")

       var

           ResEntry: Record "Reservation Entry";

       begin

           With ItemJnl do begin

               if ResEntry.FindLast then

                 ResEntry."Entry No." := ResEntry."Entry No." + 1

               else

                 ResEntry."Entry No." := 1;

               ResEntry."Item No." := ItemJnl."Item No.";

               ResEntry."Location Code" := ItemJnl."Location Code";

               ResEntry."Reservation Status" := ResEntry."Reservation Status"::Prospect;

               ResEntry."Source Type" := 83;

               ResEntry."Source Subtype" := 2;

               ResEntry."Source ID" := 'ITEM';

               ResEntry."Source Batch Name" := ItemJnl."Journal Batch Name";

               ResEntry."Source Ref. No." := ItemJnl."Line No.";

               ResEntry."Lot No." := 'TARGET';

               ResEntry."Qty. per Unit of Measure" := 1;

               ResEntry.Validate("Quantity (Base)",ItemJnl."Quantity (Base)");

               ResEntry."Creation Date" := ItemJnl."Posting Date";

               ResEntry."Expected Receipt Date" := ItemJnl."Posting Date";

               ResEntry."Warranty Date" := CalcDate('1Y',ItemJnl."Posting Date");

               ResEntry."Expiration Date" := CalcDate('1Y',ItemJnl."Posting Date");

               ResEntry.INSERT;

           end;

       end;

    Or you could something like this

                                                                                      ReserveItemJnlLine.InitTrackingSpecification(ItemJnlLine,TrackingSpecification);
                                                                                      TrackingSpecification.VALIDATE("Serial No.",SerialNo);
                                                                                      TrackingSpecification.VALIDATE("Lot No.",LotNo);
                                                                                      TrackingSpecification.VALIDATE("Quantity (Base)",ItemJnlLine.Quantity);
                                                                                     
                                                                                      ReservEntry.RESET;
                                                                                      IF ReservEntry.FINDLAST THEN
                                                                                        LastEntryNo := ReservEntry."Entry No."
                                                                                      ELSE
                                                                                        LastEntryNo := 1;
                                                                                      ReservEntry.INIT;
                                                                                      ReservEntry.TRANSFERFIELDS(TrackingSpecification);
                                                                                      ReservEntry.VALIDATE("Quantity (Base)");
                                                                                      ReservEntry.Positive := (ReservEntry."Quantity (Base)" > 0);
                                                                                      ReservEntry."Reservation Status" := ReservEntry."Reservation Status"::Prospect;
                                                                                      ReservEntry."Expected Receipt Date" := ItemJnlLine."Posting Date";
                                                                                      ReservEntry."Entry No." := LastEntryNo + 1;
                                                                                      LastEntryNo := ReservEntry."Entry No.";
                                                                                      ReservEntry.UpdateItemTracking;
                                                                                      ReservEntry.INSERT;

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,229

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,867 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,153 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans