How to check if Rec IS TEMPORARY

EugeneEugene Member Posts: 309
i need to write-protect a table but still want to allow writing to temporary version of the table

is there a way in table's code to check if the instance of a table is temporary ?

Comments

  • kinekine Member Posts: 12,562
    If you are working with temp table, in generally you are not using VALIDATE or INSERT(True) etc. (Why? Because if yes and you will modify another data within the triggers, you can have BIG problem...).
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • David_CoxDavid_Cox Member Posts: 509
    No but good Naming Conventions will help, look at the Standard Code, in the posting units you will see, TempDocDim, TempSalesLine etc:, these have thier property set to temporary.

    If you make a mistake, and do a un-condition delete, on a live table #-o

    So always test in a development server, never on the live, and check all, data (view all if you have filters), not just the couple of records you inserted. :whistle:
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • EugeneEugene Member Posts: 309
    Actually i has found a way :

    function IsTemporary() : Boolean;
    BEGIN
    RecRef.GETTABLE(Rec);
    EXIT(RecRef.NUMBER>=1000000000);
    END;
    it seems that temporary tables numbers are >=1000000000


    But i must thank kine for a very important tip that actually solved my problem
    "If you are working with temp table, in generally you are not using VALIDATE or INSERT(True) etc."
    All i had to change was MyTempRec.INSERT(TRUE) with MyTempRec.INSERT(FALSE);
  • DenSterDenSter Member Posts: 8,307
    It's not always that simple Eugene :). You should at least check what happens in the OnInsert trigger, so you can duplicate the logic if that is needed, or write your own logic. Like for instance numbering series. For sure you don't want to mess up numbering series while in a temp record, so you'll hae to write your own logic to create a new number. There may be descriptions from other tables that are populated in the Insert trigger. Just changing the parameter from TRUE to FALSE is not always the complete solution.
  • wertiswertis Member Posts: 3
    Eugene wrote: »
    function IsTemporary() : Boolean;
    BEGIN
    RecRef.GETTABLE(Rec);
    EXIT(RecRef.NUMBER>=1000000000);
    END;
    it seems that temporary tables numbers are >=1000000000
    Thanks for this! It was very helpfull for me.
  • vaprogvaprog Member Posts: 1,140
    Functionality has changed beginning with NAV 2009. You should no longer rely on a temporary Table number anymore. In fact, it does not work anymore. But Microsoft has added a property ISTEMPORARY.

    With Versions 2009 up to 2015, you still have to convert your Record to a RecordRef. Unfortunately this useful property is available for a Record variable only starting from NAV 2016.
  • archer89archer89 Member Posts: 337
    best regards
    Franz Kalchmair, MVP
    Alias: Jonathan Archer

    please like / agree / verify my answer, if it was helpful for you. thx.
    Blog: http://moxie4nav.wordpress.com/
Sign In or Register to comment.