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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Business Central forum

Entry in Tracking Specification retains though the item has been deleted from Item Journal

(0) ShareShare
ReportReport
Posted on by 114

We have imported data into Item Journal using XMLPort. When entries in Item Journal table is deleted, the respective entries in Tracking Specification table does not get deleted.

Can you please suggest whether we need to modify the below code written,

xmlport 50105 ItemJournalFileImport
{
    Caption = 'Import Item Journal CSV';
    Direction = Import;
    TextEncoding = UTF8;
    Format = VariableText;
    FieldDelimiter = '"';
    FieldSeparator = ',';

    schema
    {
        textelement(ItemJnl)
        {
            tableelement(IJL; "Item Journal Line")
            {
                AutoReplace = false;
                AutoSave = true;
                AutoUpdate = true;
                XmlName = 'ItemJournal';

                fieldelement(JnlTempName; IJL."Journal Template Name")
                {   }
                fieldelement(JnlBatchName; IJL."Journal Batch Name")
                {   }
                fieldelement(LineNo; IJL."Line No.")
                {   }
                fieldelement(ItemNo; IJL."Item No.")
                {
                    FieldValidate = yes;
                }
                fieldelement(PostingDate; IJL."Posting Date")
                {   }
                fieldelement(EntryType; IJL."Entry Type")
                {   }
                fieldelement(DocumentNo; IJL."Document No.")
                {   }
                fieldelement(Description; IJL.Description)
                {   }
                fieldelement(LocationCode; IJL."Location Code")
                {   }
                fieldelement(InvPostingroup; IJL."Inventory Posting Group")
                {   }
                fieldelement(Quantity; IJL.Quantity)
                {   }
                fieldelement(UnitCost; IJL."Unit Cost")
                {   }
                fieldelement(Amount; IJL.Amount)
                {   }
                fieldelement(UnitCostACY; IJL."Unit Cost (ACY)")
                {   }
                fieldelement(AmountACY; IJL."Amount (ACY)")
                {   }
                fieldelement(BinCode; IJL."Bin Code")
                {   }
                fieldelement(SerialNo; IJL."Serial No.")
                {   }
                fieldelement(LotNo; IJL."Lot No.")
                {   }
                fieldelement(ProfitCenterCode; IJL."Shortcut Dimension 1 Code")
                {   }
 trigger OnAfterInsertRecord()
                begin

                    if (IJL."Serial No." <> '') or (IJL."Lot No." <> ''then begin
                        TraSpec."Serial No." := IJL."Serial No.";
                        TraSpec."Lot No." := IJL."Lot No.";
                        TraSpec."Item No." := IJL."Item No.";
                        TraSpec."Entry No." := IJL."Line No.";
                        TraSpec."Location Code" := IJL."Location Code";
                        TraSpec."Quantity (Base)" := IJL.Quantity;
                        //TraSpec."" := IJL.Quantity; //Quantity field is missing in Tracking Specification table -> Quantity(Base) field is enough...
                        TraSpec."Source Type" := 83;
                        TraSpec."Source Subtype" := 2;
                        TraSpec."Source ID" := 'ITEM';
                        //TraSpec."" := 3  //Reservation Status field is missing in Tracking Specification table -> Customer field hence not required...
                        TraSpec.Positive := true;
                        TraSpec."Source Batch Name" := 'DEFAULT';
                        TraSpec."Source Ref. No." := IJL."Line No.";
                        //TraSpec."" := IJL."Posting Date"; //Expected Receipt Date field is missing in Tracking Specification table -> Custome field hence not required...
                        TraSpec."Qty. to Handle (Base)" := IJL.Quantity;
                        TraSpec."Qty. to Invoice (Base)" := IJL.Quantity;
                        TraSpec."Qty. per Unit of Measure" := 1;
                        TraSpec.Insert;
                    end;
                    TraSpec."Lot No." := '';
                    TraSpec."Serial No." := '';
                end;
            }
        }
    }
    var
        TraSpec: Record "Tracking Specification";
}
Categories:
I have the same question (0)
  • Suggested answer
    Avinash B Profile Picture
    1,455 on at

    Hi

    You must use the "Reservation Entry" table instead of Tracking Specification when you import the data.

    Regards

    Avinash B

  • Beulah Profile Picture
    114 on at

    I have used Reservation Entry Table instead of Tracking Specification table. But the reported issue still occurs... If any entry is deleted from Item Journal, the corresponding Tracking line is not getting deleted or removed from Reservation Entry/Tracking Specification. Can you please help me out ?

  • Suggested answer
    Avinash B Profile Picture
    1,455 on at

    Hi

    How are you deleting IJ? Manually or code?

    If you are deleting via code then must use Delete(true).

    Regards

    Avinash B

  • Beulah Profile Picture
    114 on at

    Manually...

    Another error we face now. We have given the condition as if Serial No or Lot No is available, then the data should be inserted into reservation table. But we are seeing entry in item tracking lines though serial no or lot no is unavailable and by default, Item Tracking Quantity is set to 1 in Item Tracking Line. How this value is set to 1 by default ? Can you please look into this ?

    if (IJL."Serial No." <> '') or (IJL."Lot No." <> '') then begin

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

                           ReservationEntry."Entry No." := IJL."Line No.";

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

                           ReservationEntry."Quantity (Base)" := IJL."Quantity";

                           ReservationEntry."Source Type" := 83;

                           ReservationEntry."Source Subtype" := 2;

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

                           ReservationEntry."Reservation Status" := 3;

                           ReservationEntry.Positive := true;

                           ReservationEntry."Source Batch Name" := 'DEFAULT';

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

                           ReservationEntry."Expected Receipt Date" := IJL."Posting Date";

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

                           ReservationEntry."Serial No." := IJL."Serial No.";

                           ReservationEntry."Lot No." := IJL."Lot No.";

                           ReservationEntry.Insert();

    end;

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

    You need to change the way you are creating Item Tracking Lines. Use the below code

    TrackingSpecification@1240060000 : Record 336;

         ReservEntry@1240060001 : Record 337;

         ReserveItemJnlLine@1240060002 : Codeunit 99000835;

         LastEntryNo@1240060003 : Integer;

         CreateReservEntry@1240060004 : Codeunit 99000830;

         ItemTrackingMgt@1240060006 : Codeunit 6500;

         CurrentEntryStatus@1240060007 : 'Reservation,Tracking,Surplus,Prospect';

         FilterReservEntry@1000000000 : Record 337;

         Item@1000000001 : Record 27;

    Item.GET(ItemJnlLine."Item No.");

           ReserveItemJnlLine.InitTrackingSpecification(ItemJnlLine,TrackingSpecification);

           TrackingSpecification.VALIDATE("Serial No.","HH Serial No.");

           TrackingSpecification.VALIDATE("Quantity (Base)",Quantity);

           IF IsReclass(ItemJnlLine) THEN

             TrackingSpecification.VALIDATE("New Serial No.","HH New Serial No.");

           IF ItemTrackingMgt.IsOrderNetworkEntity(TrackingSpecification."Source Type",

                TrackingSpecification."Source Subtype")

           THEN

             CurrentEntryStatus := CurrentEntryStatus::Surplus

           ELSE

             CurrentEntryStatus := CurrentEntryStatus::Prospect;

           IF IsReclass(ItemJnlLine) THEN BEGIN

             CreateReservEntry.SetNewSerialLotNo(

               TrackingSpecification."New Serial No.",TrackingSpecification."New Lot No.");

             CreateReservEntry.SetNewExpirationDate(TrackingSpecification."New Expiration Date");

           END;

           CreateReservEntry.SetDates(

             TrackingSpecification."Warranty Date",TrackingSpecification."Expiration Date");

           CreateReservEntry.SetApplyFromEntryNo(

             TrackingSpecification."Appl.-from Item Entry");

           CreateReservEntry.CreateReservEntryFor(

             TrackingSpecification."Source Type",

             TrackingSpecification."Source Subtype",

             TrackingSpecification."Source ID",

             TrackingSpecification."Source Batch Name",

             TrackingSpecification."Source Prod. Order Line",

             TrackingSpecification."Source Ref. No.",

             TrackingSpecification."Qty. per Unit of Measure",

             TrackingSpecification."Quantity (Base)",

             TrackingSpecification."Quantity (Base)",

             TrackingSpecification."Serial No.",

             TrackingSpecification."Lot No.");

           CreateReservEntry.CreateEntry(TrackingSpecification."Item No.",

             TrackingSpecification."Variant Code",

             TrackingSpecification."Location Code",

             TrackingSpecification.Description,

             "Posting Date",

             0D,0,CurrentEntryStatus);

  • Suggested answer
    Avinash B Profile Picture
    1,455 on at

    Firstly if you are deleting manually and if item tracking lines exist for the journal line, then there will be a confirmation dialog for deleting both IJL and ITL.

    pastedimage1568720747086v1.png

    And regarding auto-creation of ITL even if the Serial or LOT no. is blank looks very strange. I would suggest to remove the data from the table and try to import. The code looks fine. Otherwise, you can always debug to see when the record getting insert.

    Regards

    Avinash B

  • Beulah Profile Picture
    114 on at

    Can you please suggest how to delete Tracking lines from Tracking Specification Table ?

    Below code doesn't work.

    if (TrackingSpec."Source Batch Name" = 'DEFAULT') and (TrackingSpec."Source Type" = 83) and (TrackingSpec."Source Subtype" = 2) then begin

              TrackingSpec.DeleteAll();

    end;

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

News and Announcements

Season of Giving Solutions is Here!

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans