Adding a Tracking Spec Line through AL Code?

378 views Asked by At

I am trying to add Tracking Spec entry through code;

rec_trackingspec.init();

                                                      if rec_trackingspec2.FindLast() then
                                                          rec_trackingspec."Entry No." := rec_trackingspec2."Entry No." + 1 else
                                                          rec_trackingspec."Entry No." := 1;
                                                     

                                                      rec_trackingspec."Creation Date" := WorkDate();
                                                      rec_trackingspec.Positive := true;
                                                      rec_trackingspec.Validate("Item No.", rec_SalesLine."No.");
                                                      rec_trackingspec.Validate("Lot No.", rec_itemledgerentry."Lot No.");
                                                      rec_trackingspec."Location Code" := 'MAIN';
                                                
                                                      rec_trackingspec.Validate("Quantity (Base)", rec_SalesLine.Quantity);
                                                      rec_trackingspec.Validate("Bin Code", rec_SalesLine."Bin Code");
                                                      rec_trackingspec."Source Ref. No." := rec_SalesLine."Line No.";
                                                
                                                      rec_trackingspec.Insert(true);

Checking through debugger, I see Insert(true) gets executed, however when i go to check if Tracking Spec has the line I intended to insert, it does not show the entry there.

2

There are 2 answers

0
fini On

Check whether there is a code after the INSERT that reverse all the changes like an ERROR command.

2
Nyryus On

For this kind of problems I usually tend to go to SQL Server.

  • Using the debugger, debug the insert
  • Run on SQL Server, you should see the record inserted.

SELECT * FROM [Table Name] with (nolock) WHERE [KeyFields]

  • Then pressing F5 in the debugger it should stop where an error happens and the record gets deleted, if nothing like that happens, go through some lines of code with F11 and check if your records in the DB still exists, until you find which line deletes the record.

But probably in this many days you already figured it out.