How to create Item tracking line from C/AL

Question Status

Verified
Allan Borg asked a question on 5 Jan 2016 3:00 AM

Hi all!

In my custome module I have code which creates item journal lines. For these item journal lines I would like to create tracking via lot no, but I dont know how.

I would really appreciate it if someone could write an example of how to do that. I assume I have to create a TempItemTrackLine and insert it. But which variables should I set? and what to do after that?

Thanks in advance

Reply
Verified Answer
Roberto Stefanetti responded on 5 Jan 2016 3:17 AM

hi,

You don't need to write in tempitemtracking,  standard NAV "AS IS" write directly in table 337 "reservation entries" creating prospect lines for item tracking Handling.

just in time for you...  a simple example:

Tracking C/AL code exampe that write in table 337 Reservation entries

//tbl83 "Item Journal Line"   -  LOOP on jornal line existing lines

rec83.RESET;  

rec83.SETRANGE("Journal Template Name" , 'ITEM')  ;  //filter template and batch

rec83.SETRANGE("Journal Batch Name", 'INV2016');  

LotLine := 0;

IF rec83.FINDSET THEN

  REPEAT

     IF ItemHasLot(rec83."Item No.")  THEN  // function to check if item use LOTS

       BEGIN

       //Create Tracking record in table 337

       rec337."Entry No." := MaxEntry337 +1;  //recover MAX Entry No. from tbl 337

       rec337."Reservation Status" := rec337."Reservation Status"::Prospect;

       rec337."Creation Date" :=  WORKDATE;

       rec337."Source Type" := 83;

       rec337."Source Subtype" := 2;

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

       rec337."Source Batch Name" := 'INV2016';

       rec337."Source Ref. No." := rec83."Line No.";

       rec337.Positive := TRUE;

       rec337.VALIDATE("Location Code", rec83."Location Code") ;

       rec337.VALIDATE("Bin Code", rec83."Bin Code");

       rec337.VALIDATE("Item No.",rec83."Item No.");  

       rec337.VALIDATE("Quantity (Base)", rec83.Quantity);

       rec337.VALIDATE(Quantity, rec83.Quantity);

       rec337."Item Tracking" :=rec337."Item Tracking"::"Lot No." ;   // IF LOT OR TRACKING  in this sample LOT

       LotLine :=  LotLine+=;

      //Creation of LOT NO. if necessary to create a new one LOT

       IF STRLEN(FORMAT(LotLine)) = 1 THEN

          rec337."Lot No." :=  'INV16-' + '00000' + FORMAT(LotLine)  ;

       IF STRLEN(FORMAT(LotLine)) = 2 THEN

          rec337."Lot No." :=  'INV16-' + '0000' + FORMAT(LotLine)  ;

       //OR USE CASE IF YOU HAVE MORE CASES TO HANDLE

       IF  rec337.INSERT(TRUE) THEN   //If Write Tracking Line then Create LOT INFO Records

       BEGIN

       //Lot Info creation

       recLotNoIInformation.INIT:

       recLotNoIInformation.VALIDATE("Item No.", rec337."Item No.");

       recLotNoIInformation.VALIDATE("Lot No." , rec337."Lot No.");    

       recLotNoIInformation.INSERT(TRUE);

       END

       END;

  UNTIL rec83.NEXT = 0;    

i hope that cab be usefull...

Reply
Suggested Answer
Jonathan Archer responded on 5 Jan 2016 4:32 AM

you can use CU 99000830 "Create Reserv. Entry" functions CreateEntry, CreateReservEntry, CreateReservEntryFor, CreateReservEntryFrom.

Reply
Allan Borg responded on 5 Jan 2016 6:22 AM

Thanks you!

on a note: I triede to find bind code in rec337 but I could not find I so I left out thist line

rec337.VALIDATE("Bin Code", rec83."Bin Code");

Is that a problem?

Also. Do you have an example on how to reserv from this reservation line from a sales order line?

This has really been a big help.

Reply
Nareshwar R. responded on 6 Jan 2016 3:45 AM

In my scenario, I had to auto-generate the Lot Tracking Code based on the date and job number. Codeunit 99000830 is what I used and it does the job!!

Reply
Allan Borg responded on 6 Jan 2016 3:53 AM

Thanks for the reply

My issue is solved and I made use of then functions in CU 99000845 Reservation management which again makes use of 99000832 Sales Line-Reserve.

Reply
Thomas M responded on 6 Dec 2017 2:23 PM

Hey, can you tell which functions you used to solve your problem?

Thanks in advance,

Thomas

Reply
Verified Answer
Roberto Stefanetti responded on 5 Jan 2016 3:17 AM

hi,

You don't need to write in tempitemtracking,  standard NAV "AS IS" write directly in table 337 "reservation entries" creating prospect lines for item tracking Handling.

just in time for you...  a simple example:

Tracking C/AL code exampe that write in table 337 Reservation entries

//tbl83 "Item Journal Line"   -  LOOP on jornal line existing lines

rec83.RESET;  

rec83.SETRANGE("Journal Template Name" , 'ITEM')  ;  //filter template and batch

rec83.SETRANGE("Journal Batch Name", 'INV2016');  

LotLine := 0;

IF rec83.FINDSET THEN

  REPEAT

     IF ItemHasLot(rec83."Item No.")  THEN  // function to check if item use LOTS

       BEGIN

       //Create Tracking record in table 337

       rec337."Entry No." := MaxEntry337 +1;  //recover MAX Entry No. from tbl 337

       rec337."Reservation Status" := rec337."Reservation Status"::Prospect;

       rec337."Creation Date" :=  WORKDATE;

       rec337."Source Type" := 83;

       rec337."Source Subtype" := 2;

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

       rec337."Source Batch Name" := 'INV2016';

       rec337."Source Ref. No." := rec83."Line No.";

       rec337.Positive := TRUE;

       rec337.VALIDATE("Location Code", rec83."Location Code") ;

       rec337.VALIDATE("Bin Code", rec83."Bin Code");

       rec337.VALIDATE("Item No.",rec83."Item No.");  

       rec337.VALIDATE("Quantity (Base)", rec83.Quantity);

       rec337.VALIDATE(Quantity, rec83.Quantity);

       rec337."Item Tracking" :=rec337."Item Tracking"::"Lot No." ;   // IF LOT OR TRACKING  in this sample LOT

       LotLine :=  LotLine+=;

      //Creation of LOT NO. if necessary to create a new one LOT

       IF STRLEN(FORMAT(LotLine)) = 1 THEN

          rec337."Lot No." :=  'INV16-' + '00000' + FORMAT(LotLine)  ;

       IF STRLEN(FORMAT(LotLine)) = 2 THEN

          rec337."Lot No." :=  'INV16-' + '0000' + FORMAT(LotLine)  ;

       //OR USE CASE IF YOU HAVE MORE CASES TO HANDLE

       IF  rec337.INSERT(TRUE) THEN   //If Write Tracking Line then Create LOT INFO Records

       BEGIN

       //Lot Info creation

       recLotNoIInformation.INIT:

       recLotNoIInformation.VALIDATE("Item No.", rec337."Item No.");

       recLotNoIInformation.VALIDATE("Lot No." , rec337."Lot No.");    

       recLotNoIInformation.INSERT(TRUE);

       END

       END;

  UNTIL rec83.NEXT = 0;    

i hope that cab be usefull...

Reply
Suggested Answer
Jonathan Archer responded on 5 Jan 2016 4:32 AM

you can use CU 99000830 "Create Reserv. Entry" functions CreateEntry, CreateReservEntry, CreateReservEntryFor, CreateReservEntryFrom.

Reply