Follow me on Twitter

A technical eye on Microsoft Dynamics NAV

How to add new fields to the Item Tracking Lines form

in Development by Ian Crocker


Photo credit: Bruno Girin

The Item Tracking Lines form has a Source Table of Tracking Specification.

The Tracking Specification table is used in conjunction with theResrevation Entry table, Item Ledger Entry table and various temporary record handling functionality in order to attach and maintain tracking against items on document lines.

To add a new field, for example, Your Reference, you must first add this field to the Tracking Specification table and place it on screen by modifying the Item Tracking Lines form:

Reservation Entry

The new field also needs to be added to the Reservation Entry table. 

Unfortunately there is more to it than just placing the field on screen. If you try to assign a lot and fill in our new Your Reference field, close the form, then re-open, you’ll notice that the value entered has disappeared.

This is beause the new field needs to be pushed through to the Reservation Entry table.

To achieve this we need to delve into the code behind the Item Tracking Lines form.

RegisterChange

The first function we need to look at is the the RegisterChange function. 

Within this function there is a call to the CreateReservEntryFor function in the Create Reserv. Entrycodeunit. Values are passed to this function which is then used to update the reservation entries.

You can either modify the CreateReservEntryFor function and tag your field(s) on the end, or create a new function called SetCustomFields which will take your new field(s) as parameters.

The new function should look something like this:

SetCustomFields(YourReference : Text[30])
  1. InsertReservEntry."Your Reference" := YourReference;
  2. InsertReservEntry2."Your Reference" := YourReference;

A call to this new function must then be made from the RegisterChange function in the Item Tracking Lines form.

OK := FALSE;
  1. IF CurrentSignFactor < 0 THEN
  2.   NewTrackingSpecification."Expiration Date" := 0D;
  3.  
  4. CASE ChangeType OF
  5.   ChangeType::Insert:
  6.     BEGIN
  7.       IF (OldTrackingSpecification."Quantity (Base)" = 0) OR
  8.          ((OldTrackingSpecification."Lot No." = '') AND
  9.           (OldTrackingSpecification."Serial No." = ''))
  10.       THEN
  11.         EXIT(TRUE);
  12.       TempReservEntry.SETRANGE("Serial No.",'');
  13.       TempReservEntry.SETRANGE("Lot No.",'');
  14.       OldTrackingSpecification."Quantity (Base)" :=
  15.         CurrentSignFactor *
  16.         ReservEngineMgt.AddItemTrackingToTempRecSet(
  17.           TempReservEntry,NewTrackingSpecification,
  18.           CurrentSignFactor * OldTrackingSpecification."Quantity (Base)",QtyToAddAsBlank,
  19.           ItemTrackingCode."SN Specific Tracking",ItemTrackingCode."Lot Specific Tracking");
  20.       TempReservEntry.SETRANGE("Serial No.");
  21.       TempReservEntry.SETRANGE("Lot No.");
  22.  
  23.       // Late Binding
  24.       IF ReservEngineMgt.RetrieveLostReservQty(LostReservQty) THEN BEGIN
  25.         TempItemTrackLineReserv := OldTrackingSpecification;
  26.         TempItemTrackLineReserv."Quantity (Base)" := LostReservQty * CurrentSignFactor;
  27.         TempItemTrackLineReserv.INSERT;
  28.       END;
  29.  
  30.       IF OldTrackingSpecification."Quantity (Base)" = 0 THEN
  31.         EXIT(TRUE);
  32.  
  33.       IF (FormRunMode = FormRunMode::Reclass) OR MoveBinContent THEN BEGIN
  34.         CreateReservEntry.SetNewSerialLotNo(
  35.           OldTrackingSpecification."New Serial No.",OldTrackingSpecification."New Lot No.");
  36.         CreateReservEntry.SetNewExpirationDate(OldTrackingSpecification."New Expiration Date");
  37.       END;
  38.       CreateReservEntry.SetDates(
  39.         NewTrackingSpecification."Warranty Date",NewTrackingSpecification."Expiration Date");
  40.       CreateReservEntry.SetApplyFromEntryNo(
  41.         NewTrackingSpecification."Appl.-from Item Entry");
  42.  
  43.       CreateReservEntry.SetCustomFields("Your Reference"); // — INSERT LINE ++
  44.  
  45.       CreateReservEntry.CreateReservEntryFor(
  46. ..
  47. ..

The new field will now be pushed through to the reservation entry table when the item tracking form is in insert mode.

It also needs to update correctly when in modify/delete mode.

EntriesAreIdentical

To do this you firstly need to modify the EntriesAreIdentical function by inserting the new Your Reference field as follows:

..
  1. ..
  2. IdenticalArray[2] := (
  3.   (ReservEntry1.Description = ReservEntry2.Description) AND
  4.   (ReservEntry1."New Serial No." = ReservEntry2."New Serial No.") AND
  5.   (ReservEntry1."New Lot No." = ReservEntry2."New Lot No.") AND
  6.   (ReservEntry1."Expiration Date" = ReservEntry2."Expiration Date") AND
  7.   (ReservEntry1."Warranty Date" = ReservEntry2."Warranty Date") AND
  8.   (ReservEntry1."Your Reference" = ReservEntry2."Your Reference") AND // — INSERT LINE ++
  9.   (ReservEntry1."New Expiration Date" = ReservEntry2."New Expiration Date"));
  10. EXIT(IdenticalArray[1] AND IdenticalArray[2]);

RegisterChange

Now we need to go back to the RegisterChange function and insert the following two lines of code which fall within ChangeType::Modify: case statement.

This code will update the reservation entries correctly when our new field Your Reference is modified.

TempReservEntry.SETRANGE(“Lot No.”); 
  1.  
  2. // Late Binding
  3. IF ReservEngineMgt.RetrieveLostReservQty(LostReservQty) THEN BEGIN
  4.   TempItemTrackLineReserv := OldTrackingSpecification;
  5.   TempItemTrackLineReserv."Quantity (Base)" := LostReservQty * CurrentSignFactor;
  6.   TempItemTrackLineReserv.INSERT;
  7. END;
  8.  
  9. OldTrackingSpecification."Quantity (Base)" := QtyToAdd;
  10. OldTrackingSpecification."Warranty Date" := NewTrackingSpecification."Warranty Date";
  11. OldTrackingSpecification."Expiration Date" := NewTrackingSpecification."Expiration Date";
  12. OldTrackingSpecification.Description := NewTrackingSpecification.Description;
  13. // — INSERT FOLLOWING LINE ++
  14. OldTrackingSpecification."Your Reference" := NewTrackingSpecification."Your Reference";
  15. RegisterChange(OldTrackingSpecification,OldTrackingSpecification,
  16. ChangeType::Insert,NOT IdenticalArray[2]);
  17. END ELSE BEGIN
  18. TempReservEntry.SETRANGE("Serial No.",OldTrackingSpecification."Serial No.");
  19. TempReservEntry.SETRANGE("Lot No.",OldTrackingSpecification."Lot No.");
  20. OldTrackingSpecification."Serial No." := '';
  21. OldTrackingSpecification."Lot No." := '';
  22. OldTrackingSpecification."Warranty Date" := 0D;
  23. OldTrackingSpecification."Expiration Date" := 0D;
  24. // — INSERT FOLLOWING LINE ++
  25. OldTrackingSpecification."Your Reference" := '';
  26. QtyToAdd :=

ModifyFieldsWithinFilter

Lastly we need to add a line of code to the ModifyFieldsWithinFilter function:

// Used to ensure that field values that are common to a SN/Lot are copied to all entries.
  1. IF ReservEntry1.FIND('-') THEN
  2.   REPEAT
  3.     ReservEntry1.Description := TrackingSpecification.Description;
  4.     ReservEntry1."Warranty Date" := TrackingSpecification."Warranty Date";
  5.     ReservEntry1."Expiration Date" := TrackingSpecification."Expiration Date";
  6.     ReservEntry1."New Serial No." := TrackingSpecification."New Serial No.";
  7.     ReservEntry1."New Lot No." := TrackingSpecification."New Lot No.";
  8.     ReservEntry1."New Expiration Date":= TrackingSpecification."New Expiration Date";
  9.     // — INSERT FOLLOWING LINE ++
  10.     ReservEntry1."Your Reference":= TrackingSpecification."Your Reference";
  11.     ReservEntry1.MODIFY;
  12.   UNTIL ReservEntry1.NEXT = 0;

The new field should now be fully operational.

2 Comments

  1. Belias

    hi, i found 2 more places that we need to update, i’ll post here a link to mibuso, where the discussion started (and where i posted a piece of code)
    http://www.mibuso.com/forum/viewtopic.php?f=23&t=41397&p=204057#p204057

    The 2 functions you didn’t wrote in your (wonderful) blog post, allow us to keep our new fields after posting a transfer order or a production order.
    to avoid my cross posting, can you update your blog post when possible, please?
    Thanks for your effort!!!

Leave a response

What's cooking?

Photo credits

View Ian Crocker's profile on LinkedIn