A safe way to use temporary records

samantha73samantha73 Member Posts: 106
edited 2021-10-30 in NAV Three Tier
Hi Guys
I have tried a couple of variations of the temporary record to display results on a page and report. First below example
var
                    TempVend: Record Vendor temporary;
                begin
                    TempVend.Init();
                    TempVend."No." := '30000';
                    TempVend.Insert();
                    TempVend."No." := '10000';
                    TempVend.Insert();
                    TempVend."No." := 'blah';
                    TempVend.Insert();
                    [b]TempVend.deleteall(true);[/b]

The problem is with table trigger = true , it deletes related records. I have seen recommendations to use above without true such as deleteall() but the problem is by mistake someone else can modify this code to True or I can leave True and actually delete records on the source actual table.
So I prefer creating a brand new table of with:
TableType = Temporary;

Now I have to populate this table and display on a page at run time and if required I can union other tables. Same can be done on RDLC reports using an integer data item.

So I think the first pattern of setting an existing table to temporary is dangerous and I'm not sure why it still exists?

Answers

  • jordi79jordi79 Member Posts: 277
    Hi Samantha,
    It is a good practice to test the variable to ensure it is temp. You can use ISTEMPORARY() to test the temp variables.

    I have had the same issue where I accidentally deleted records because of this, and this is made worst, if there are several developers working on the same problem.
    Jordi
  • samantha73samantha73 Member Posts: 106
    Thanks for the tip on ISTEMPORARY. The point I'm making is we are leaving this pattern open to mistakes by someone later on and coding in AL is not intuitive, perhaps this is why the average age of a BC programmer is like 41 years (from DIRECTIONS EMEA slide) meaning only people with tons of experience can know the hidden gotchas.
Sign In or Register to comment.