Codementor Events

Adopting Item Tracking Line Functionality With Another Table

Published Dec 19, 2018

At first, I never thought that implementing the item tracking line functionality outside the standard Item Tracking Line page will be quite complex and tricky.

The idea is simple: Imagine a scenario, where we need to input a single lot no. for every single line of Item Journal. It means: a single item journal line will always consists of one item tracking line. This is quite contrast to what Dynamics NAV offers. The process of selecting/entering Lot No. using Item Tracking Lines page will be lengthy since there are hundreds of item journal line with each one of them has only one lot no.

microsoft-dynamics-nav-client_2018-12-08_13-00-04.png
Imagine when you have to enter lot no. one-by-one to each line using the standard Item Tracking Line page, and there are hundreds line of it. Each line has different lot no.. Oh boy…

Table Design

If you need a different table to do that you might need to adjust this article based on what you want. You’re lucky if you’re just modifying the standard item journal line.

For this article I will use two tables: one, NewSelectTable, for the selecting item tracking for sale/negative adjustment and the other one, NewInsertTable,  is for inserting item tracking for purchase/positive adjustment.

Inserting Item Tracking for Purchase/Positive Adjustment

Inserting item tracking is pretty forward, we only need to check whether the item tracking (lot no./serial no.) has been inserted, and thus let the rest is handled by system internal code.

The code is somehow like this:

CreateReservEntry@1000000002 : Codeunit 99000830;
ProcessSpecification@1000000003 : Record 336; CreateReservEntry.SetDates(0D, 0D);
CreateReservEntry.CreateReservEntryFor(
DATABASE::"New Insert Table", 0,
NewInsertTable."Document No.", '', 0, NewInsertTable."Line No.", NewInsertTable."Qty. Per Unit of Measure",
NewInsertTable.Quantity, NewInsertTable."Quantity (Base)", '', NewInsertTable."Lot No.");
CreateReservEntry.CreateEntry(NewInsertTable."Item No.", '', NewInsertTable."Location Code",
NewInsertTable.Description, 0D, 0D, 0, 3); // prospect

The rest is we need to create a default Item Journal Line for posting purchase/positive adjustment, and post that Line using codeunit Item Jnl.-Post Line (22).

Selecting Item Tracking for Sale/Negative Adjustment

However, the selecting item tracking is more complex because, by default, any exception occurred upon selecting item tracking is handled by page Item Tracking Lines (6510). If we need to use a separate table to do the selecting, we need to carry forward the process of checking the item tracking into our code.

Consider this scenario:

  1. Item A, Lot No. #123 is registered to have 1000 PCS in the Item Ledger Entry.
  2. We decide to take 500 PCS and put that into our new select table – without reserving that entry. Reserving an entry is best choice, but it gives another responsibility: maintaining reservation if the line is deleted.
  3. Then another process uses that entry for 700 PCS (either for manufacture or sudden sale), thus, 500 PCS isn’t sufficient.

It’s true, this scenario wouldn’t happen if we’re using standard Dynamics NAV Item Tracking functionality. In here, we only can take a precaution before posting the sale/negative adjustment, we can continue the process only if the quantity is enough.

First, we need to create a reservation entry before doing the sale/negative adjustment:

_ReservationEntry@1011 : Record 337;
_ReservationEntryNo@1012 : Integer;
_ReservationEntryNo := 1;
_ReservationEntry.RESET;
_ReservationEntry.SETRANGE(Positive,FALSE);
IF _ReservationEntry.FINDLAST THEN
_ReservationEntryNo := _ReservationEntry."Entry No." + 1;

_ReservationEntry.INIT;
_ReservationEntry."Entry No." := _ReservationEntryNo;
_ReservationEntry."Item No." := NewSelectTable."Item No.";
_ReservationEntry."Location Code" := NewSelectTable."Location Code";
_ReservationEntry."Quantity (Base)" := -1 * NewSelectTable."Qty. to be Processed" * NewSelectTable."Qty. per Unit of Measure";
_ReservationEntry."Quantity Invoiced (Base)" := -1 * NewSelectTable."Qty. to be Processed" * NewSelectTable."Qty. per Unit of Measure";
_ReservationEntry."Reservation Status" := _ReservationEntry."Reservation Status"::Prospect;
_ReservationEntry."Creation Date" := NewSelectTable."Posting Date";
_ReservationEntry."Source Type" := DATABASE::"Item Journal Line";
_ReservationEntry."Source Subtype" := _ItemJnlLine."Entry Type"::"Negative Adjmt.";
_ReservationEntry."Source ID" := NewSelectTable."No.";
_ReservationEntry."Source Batch Name" := ''; // NEED BLANK TO DIFFERENTIATE POSTING FROM CODE
_ReservationEntry."Source Ref. No." := NewSelectTable."Line No.";
_ReservationEntry."Shipment Date" := NewSelectTable."Posting Date";
_ReservationEntry."Serial No." := NewSelectTable."Serial No.";
_ReservationEntry."Created By" := USERID;
_ReservationEntry.Positive := FALSE;
_ReservationEntry."Qty. per Unit of Measure" := NewSelectTable."Qty. per Unit of Measure";
_ReservationEntry.Quantity := -1 * NewSelectTable."Qty. to be Processed";
_ReservationEntry."Appl.-to Item Entry" := NewSelectTable."ILE Entry No.";
_ReservationEntry."Qty. to Handle (Base)" := -1 * NewSelectTable."Qty. to be Processed" * NewSelectTable."Qty. per Unit of Measure";
_ReservationEntry."Qty. to Invoice (Base)" := -1 * NewSelectTable."Qty. to be Processed" * NewSelectTable."Qty. per Unit of Measure";
_ReservationEntry."Lot No." := NewSelectTable."Lot No.";
_ReservationEntry.INSERT();

Then we need to make sure the inserted reservation is enough for the negative adjustment posting.

_ProcessSpecification@1015 : Record 336; 
_ProcessSpecification.CheckItemTrackingQuantity(DATABASE::"Item Journal Line",
_ItemJnlLine."Entry Type"::"Negative Adjmt.",
NewSelectTable."No.",
NewSelectTable."Line No.",
NewSelectTable."Qty. to be Processed" * NewSelectTable."Qty. per Unit of Measure",
NewSelectTable."Qty. to be Processed" * NewSelectTable."Qty. per Unit of Measure",
TRUE, TRUE);

The rest is we need to create a default Item Journal Line for posting sale/negative adjustment, and post that Line using codeunit Item Jnl.-Post Line (22).

Modifying the Item Journal Post Process

Following our scenario: I used different tables to hold the Lot No. data either for selecting and inserting so another customization is needed. You can skip this IF you’re using standard Item Journal Line.

Dynamics NAV always re-route every single item transaction through item journal line. If we decide not to use Item Journal Line as the base of our enter/select item tracking then we need another further customization.

Adding new functions into Item Tracking Management (6500)

We’ll need something similar to this code. In short, this function will select the reservation entries from the new tables instead of from the regular item journal line.

PROCEDURE RetrieveNewInsertTableItemTracking@110(NewInsertTable@1002 : Record 50000;
VAR pTempHandlingSpecification@1007 : TEMPORARY Record 336) : Boolean;
VAR ReservEntry@1001 : Record 337;
BEGIN 
ReservEntry.SETCURRENTKEY( "Source ID","Source Ref. No.","Source Type","Source Subtype", "Source Batch Name","Source Prod. Order Line"); ReservEntry.SETRANGE("Source ID", NewInsertTable."Document No."); ReservEntry.SETRANGE("Source Ref. No.", NewInsertTable."Line No."); ReservEntry.SETRANGE("Source Type", DATABASE::"New Insert Table"); ReservEntry.SETRANGE("Source Batch Name",''); ReservEntry.SETRANGE("Source Prod. Order Line",0); ReservEntry.SETFILTER("Qty. to Handle (Base)",'<>0'); 
IF SumUpItemTracking(ReservEntry,pTempHandlingSpecification,FALSE,TRUE) THEN BEGIN 
ReservEntry.SETRANGE("Reservation Status",ReservEntry."Reservation Status"::Prospect); 
IF NOT ReservEntry.ISEMPTY THEN 
ReservEntry.DELETEALL; 
EXIT(TRUE); 
END; 
EXIT(FALSE);
END;

Modifying the Codeunit Item Jnl.-Post Line (22)

Last thing we need, if we use different tables, is assigning the function RetrieveNewInsertTableItemTracking to item journal process. The idea is to redirect the RetrieveItemTracking if we are using different tables.

In here, to make things easy to find which Item Journal Lines that are created from the new tables, I did a bit modification to Item Ledger Entry and Item Journal Line: a new option to Document Type field to separate the new table.

This code should be place inside the SetupSplitJnlLine function.

_OK@1000000000 : Boolean; 
IF ItemJnlLineOrigin."Document Type" = ItemJnlLineOrigin."Document Type"::"New Document Type" THEN BEGIN 
_OK := NOT ItemJnlLine2.Correction AND (ItemJnlLine2.Quantity <> 0); 
IF _OK THEN BEGIN 
CASE ItemJnlLineOrigin."Entry Type" OF 
ItemJnlLineOrigin."Entry Type"::"Positive Adjmt." : 
_OK := ItemTrackingMgt.RetrieveNewInsertTableItemTracking(NewInsertTable, TempTrackingSpecification); 
ItemJnlLineOrigin."Entry Type"::"Negative Adjmt." : 
_OK := ItemTrackingMgt.RetrieveNewSelectTableItemTracking(NewSelectTable, TempTrackingSpecification); 
END; 
END;
END ELSE
//>> the original Dynamics NAV code goes below
_OK := NOT ItemJnlLine2.Correction AND (ItemJnlLine2."Quantity (Base)" <> 0) AND ItemTrackingMgt.RetrieveItemTracking(ItemJnlLine2,TempTrackingSpecification);

That’s all. Now you should have working modification of posting process Lot No./Serial No. without using the Item Tracking Line page.

Discover and read more posts from Ariestya Dibyanugraha
get started
post commentsBe the first to share your opinion
Show more replies