Create Positive Item Journal Adjustments with auto Item tracking:
(1) In every type of industry where Items are Purchase, Sales and Manufacture, at the time of
adjusting the inventory, we mainly used “Physical Journals” while using this Physical Journal, we
have to apply lot no. or item tracking one by one. Due to this reason, we will develop the same
functionality with auto-assignment of lot no. or item tracking.
(2) For developing the above functionality, follow the below screenshots.
Create a New function. In the below example I have created a function in CodeUnit. I am creating Positive Adjustment entries as Shown.
![Create Positive Item Journal Adjustments with auto Item tracking or Lot No. assignment in BC D365 1 Create Positive Item Journal Adjustments Codeunit 1](https://i0.wp.com/erpconsultors.com/wp-content/uploads/2022/02/Create-Positive-Item-Journal-Adjustments-Codeunit-1.png?resize=650%2C387&ssl=1)
![Create Positive Item Journal Adjustments with auto Item tracking or Lot No. assignment in BC D365 2 Create Positive Item Journal Adjustments codeunit 2](https://i0.wp.com/erpconsultors.com/wp-content/uploads/2022/02/Create-Positive-Item-Journal-Adjustments-codeunit-2.png?resize=655%2C205&ssl=1)
![Create Positive Item Journal Adjustments with auto Item tracking or Lot No. assignment in BC D365 3 Create Positive Item Journal Adjustments codeunit 3](https://i0.wp.com/erpconsultors.com/wp-content/uploads/2022/02/Create-Positive-Item-Journal-Adjustments-codeunit-3.png?resize=655%2C159&ssl=1)
![Create Positive Item Journal Adjustments with auto Item tracking or Lot No. assignment in BC D365 4 Create Positive Item Journal Adjustments codeunit 4](https://i0.wp.com/erpconsultors.com/wp-content/uploads/2022/02/Create-Positive-Item-Journal-Adjustments-codeunit-4.png?resize=655%2C153&ssl=1)
![Create Positive Item Journal Adjustments with auto Item tracking or Lot No. assignment in BC D365 5 Create Positive Item Journal Adjustments codeunit 5](https://i0.wp.com/erpconsultors.com/wp-content/uploads/2022/02/Create-Positive-Item-Journal-Adjustments-codeunit-5.png?resize=655%2C336&ssl=1)
Source Code:
codeunit 50000 “Custom Functions” { trigger OnRun() begin end; var myInt: Integer; local procedure CreatePositiveItemJournalLines(ItemNo: Code[20]) var ReservationEntry: Record “Reservation Entry”; CheckReservationEntry: Record “Reservation Entry”; DeleteReservationEntry: Record “Reservation Entry”; GetItem: Record Item; CheckItemJournalLine: Record “Item Journal Line”; ItemJournalLine: Record “Item Journal Line”; ItemLedgerEntry: Record “Item Ledger Entry”; EntryNo: Integer; LineNo: Integer; begin GetItem.RESET; GetItem.SETFILTER(“No.”, ItemNo); IF GetItem.FINDSET THEN BEGIN REPEAT DeleteReservationEntry.RESET; DeleteReservationEntry.SETRANGE(“Item No.”, GetItem.”No.”); DeleteReservationEntry.SETFILTER(“Source Type”, ‘<>%1’, 5741); IF DeleteReservationEntry.FINDSET THEN BEGIN REPEAT IF NOT (DeleteReservationEntry.”Location Code” IN [‘INTRNSIT’, ‘JOBWORK-OT’, ‘SALE-JW-IN’, ‘SALE-JW-OT’]) THEN DeleteReservationEntry.DELETE; UNTIL DeleteReservationEntry.NEXT = 0; END; ItemLedgerEntry.RESET; ItemLedgerEntry.SETRANGE(“Item No.”, GetItem.”No.”); ItemLedgerEntry.SETFILTER(“Remaining Quantity”, ‘<>%1’, 0); //ItemLedgerEntry.SETFILTER(“Posting Date”,’..%1′,310321D); IF ItemLedgerEntry.FINDSET THEN BEGIN REPEAT IF NOT (ItemLedgerEntry.”Location Code” IN [‘INTRNSIT’, ‘JOBWORK-OT’, ‘SALE-JW-IN’, ‘SALE-JW-OT’]) THEN BEGIN CheckItemJournalLine.RESET; CheckItemJournalLine.SETRANGE(“Journal Template Name”, ‘ITEM’); CheckItemJournalLine.SETRANGE(“Journal Batch Name”, ‘DEFAULT’); IF CheckItemJournalLine.FINDLAST THEN LineNo := CheckItemJournalLine.”Line No.” + 10000 ELSE LineNo := 10000; ItemJournalLine.INIT; ItemJournalLine.VALIDATE(“Journal Template Name”, ‘ITEM’); ItemJournalLine.VALIDATE(“Journal Batch Name”, ‘DEFAULT’); ItemJournalLine.”Line No.” := LineNo; ItemJournalLine.VALIDATE(“Posting Date”, TODAY); ItemJournalLine.”Document No.” := ItemLedgerEntry.”Document No.”; ItemJournalLine.VALIDATE(“Entry Type”, ItemJournalLine.”Entry Type”::”Positive Adjmt.”); ItemJournalLine.VALIDATE(“Item No.”, GetItem.”No.”); ItemJournalLine.VALIDATE(Quantity, ItemLedgerEntry.”Remaining Quantity”); ItemJournalLine.VALIDATE(“Location Code”, ItemLedgerEntry.”Location Code”); ItemJournalLine.VALIDATE(“Posting No. Series”, ‘ITJ’); ItemJournalLine.INSERT; IF GetItem.”Item Tracking Code” <> ” THEN BEGIN CheckReservationEntry.RESET; CheckReservationEntry.SETFILTER(“Entry No.”, ‘<>%1’, 0); IF CheckReservationEntry.FINDLAST THEN EntryNo := 1 + CheckReservationEntry.”Entry No.” ELSE EntryNo := 1; ReservationEntry.INIT; ReservationEntry.”Entry No.” := EntryNo; ReservationEntry.Positive := FALSE; ReservationEntry.”Item No.” := ItemJournalLine.”Item No.”; ReservationEntry.”Location Code” := ItemJournalLine.”Location Code”; ReservationEntry.”Reservation Status” := ReservationEntry.”Reservation Status”::Prospect; ReservationEntry.Description := ItemJournalLine.Description; ReservationEntry.”Creation Date” := ItemJournalLine.”Posting Date”; ReservationEntry.”Source Type” := 83; ReservationEntry.”Source Batch Name” := ItemJournalLine.”Journal Batch Name”; ReservationEntry.”Source ID” := ItemJournalLine.”Journal Template Name”; ReservationEntry.”Source Subtype” := 2; ReservationEntry.”Source Ref. No.” := ItemJournalLine.”Line No.”; ReservationEntry.”Expected Receipt Date” := ItemJournalLine.”Posting Date”; ReservationEntry.”Lot No.” := ItemLedgerEntry.”Lot No.”; ReservationEntry.Positive := True; ReservationEntry.VALIDATE(“Quantity (Base)”, ABS(ItemLedgerEntry.”Remaining Quantity”)); ReservationEntry.”Qty. per Unit of Measure” := 1; ReservationEntry.”Item Tracking” := ReservationEntry.”Item Tracking”::”Lot No.”; ReservationEntry.INSERT; END; END; UNTIL ItemLedgerEntry.NEXT = 0; END; UNTIL GetItem.NEXT = 0; END; end; } |