Create NegativeItem Journal Adjustments with auto Item tracking or Lot No. assignment in BC D365

NegativeItem Journal Adjustments with auto Item tracking or Lot No. Assignment:

(1) In every type of industry where Items are Purchase, Sales & 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 New function. In the below example I have created a function in CodeUnit. I am creating Negative Adjustment entries as shown.

Create Negative Item Journal Line in BC D365
Handling of those reservation entries which are attached with other entries in bc d365
Negative Adjustment entries code unit in bc d365
This Section create Reservation Entry for auto assignment of Lot no. or item tracking for negative adjustment entries

Source Code:

codeunit 50000 “Custom Functions”
{
    trigger OnRun()
    begin
    end;
 
    var
myInt: Integer;
 
    local procedure CreateNegativeItemJournalLines(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”::”Negative 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” := 3;
ReservationEntry.”Source Ref. No.” := ItemJournalLine.”Line No.”;
ReservationEntry.”Expected Receipt Date” := ItemJournalLine.”Posting Date”;
ReservationEntry.”Lot No.” := ItemLedgerEntry.”Lot No.”;
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;
}

Take Database Backup via SQL Query in SQL Server
Create Database via query in SQL Server
How to Take BACKUP from SQL Database
Development of Trial Balance Report in BC D365
Creation and Usage of Temporary Table in BC D365
How to configure GST Setup in Dynamics 365 BC
Create and work with custom fields– Microsoft Docs

Leave a Reply