Viewing Temp tables on Forms

MagnoMagno Member Posts: 168
edited 2007-12-07 in NAV Tips & Tricks
Everybody has already stumbled against the problem of viewing temp tables in forms used for viewing, not for adding or deleting(however this is possible too).

-First you set the sourcetable to the same ID as the temp table.
-on OpenForm or wherever(like push on button) fill the temp table.(PUT A RESET AFTER FILLING IT!!)

OnFindRecord(Which : Text[1024]) : Boolean
<Temp table>.COPY(Rec);
IF NOT <Temp table>.FIND(Which) THEN
EXIT(FALSE);
Rec := <Temp table>;

EXIT(TRUE);

__________________________

OnNextRecord(Steps : Integer) : Integer
//MAKE A LOCAL INTEGER liCurrentSteps
<Temp Table>.COPY(Rec);
liCurrentSteps := <Temp Table>.NEXT(Steps);
IF liCurrentSteps <> 0 THEN
Rec := <Temp Table>;
EXIT( liCurrentSteps);


Probably many of you will have used something similar, the copy line is one I added, this line makes sure you can even use filters,keys,... on the lines.
There are no bugs, only random undocumented features...
---
My Blog: http://NAV-Magno.be

Comments

  • ara3nara3n Member Posts: 9,256
    You can open temporary recods on a form by just

    TempItem."No." := 'tada';
    TempItem.INSERT;
    
    FORM.RUNMODAL(FORM::"Item list",TempItem);
    
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Miklos_HollenderMiklos_Hollender Member Posts: 1,598
    It depends. Sometimes stuff gets more complicated than that. It's good to check F542, Dimensions Multiple. This is where you can set a dimension and value pair for many f.e. Items at once. There are 3 temp tables in global variables, if I remember correctly, it's TempDefaultDim, TempDefaultDim2, TempDefaultDim3. TempDefaultDim3 contains one entry for each Item you selected - basically a simple saving of your selection. TempDefaultDim2 contains the old dimension code-value pairs of the selected Items. TempDefaultDim is the working table where the users sets the new codes and new values.

    It's advisable to check this out. One can learn a lot here.
  • MTCMTC Member Posts: 159
    Everybody has already stumbled against the problem of viewing temp tables in forms used for viewing, not for adding or deleting(however this is possible too).

    Yes, you have to add:

    Form - OnInsertRecord(BelowxRec : Boolean) : Boolean
    <Temp Table>.COPY(Rec);
    <Temp Table>.INSERT;
    EXIT(FALSE);

    Form - OnModifyRecord() : Boolean
    <Temp Table>.COPY(Rec);
    <Temp Table>.MODIFY;
    EXIT(FALSE);

    Form - OnDeleteRecord() : Boolean
    <Temp Table>.COPY(Rec);
    <Temp Table>.DELETE;
    EXIT(FALSE);

    For inserting, you will still have to deal with the value of the primary key, remembering that AutoIncrement doesn't work on temporary tables.
  • jordi79jordi79 Member Posts: 275
    Hi MTC,

    Thank you. This coding snippet is really a life saver. I was looking and trying so hard on getting nav forms to display and allow edit and insert to temp tables.

    Thanks.
  • WaldoWaldo Member Posts: 3,412
    Did you look at the "SourceTableTemporary" property.

    Mark explained it once in one of his blog posts. You can find it here.

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • jordi79jordi79 Member Posts: 275
    No way I can do that. Customer is using NAV 4SP3.

    After doing the development half way through... i realised that the table is a main form, sub form relation. This makes implementing this using a temp source table much more complicated now...

    Actually, what i wanted to achieve with temp table, is so that a user can make changes to a setup table (as much as they like), and commit the changes (and run some update processes here...) when the user leaves the form.

    I cannot put the update processes in the Onvalidate trigger (or any record related triggers...) as the update processes are very taxing to the system.
Sign In or Register to comment.