How to know that Record.GET has been already executed ?

amer
amer Member Posts: 22
To avoid unnecessary DB traffic I want to do GlSetup.GET only once because it is Global variable (GlSetup is "General Ledger Setup" tables) but there is no way to detect for a Record variable that Record.GET has been already executed.
(I need GlSetup to handle validation triggers for some fields in another table)

I could use some GetFlag boolean variable to set it TRUE after GET statement but is there any more convenient way?
(ISEMPTY, COUNT, GETPOSITION are useless, Table GlSetup has Primary key always blank, etc)

Best Regards,
Amer

Comments

  • ara3n
    ara3n Member Posts: 9,258
    Store it in TempGLSetup table and then you don't have to do get

    for example

    function GETGLSetup()
    if not TempGLSetup.get then begin
    GLSETUP.get;
    TempGLSetup := GLSETUP;
    TempGLSetup.insert;
    end;


    This way you can use TempGLSetup and all you have to do is call GETGLSetup everywhere.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • DenSter
    DenSter Member Posts: 8,307
    Check out Codeunit 90:
    GetGLSetup()
    IF NOT GLSetupRead THEN
      GLSetup.GET;
    GLSetupRead := TRUE;
    
    GLSetupRead is a global boolean variable
  • DenSter
    DenSter Member Posts: 8,307
    No that is just bad advice, you can't simply replace FIND('-') with FINDFIRST.
  • SteveO
    SteveO Member Posts: 164
    In the above example you can.
    He never said that you should replace all FIND('-') with FINDFIRST.
    He said in examples such as that, it is possible.
    This isn't a signature, I type this at the bottom of every message
  • DenSter
    DenSter Member Posts: 8,307
    In some cases you can make that replacement, but the post implies that it is always the case, and that would be bad advice.
  • bbrown
    bbrown Member Posts: 3,268
    FINDFIRST vs. FIND('-') only makes a difference on SQL. It change the way in which SQL builds its cursors. The two commands behave the same way on the native database.
    There are no bugs - only undocumented features.
  • amer
    amer Member Posts: 22
    It's just NOT a problem what you need to care about.

    It's doesn't created any traffic after first call. Navision has own data cache.

    I am not so sure. Try to use Client Monitor or SQL profiler. Every time I issue GLSetup.GET(), there are at least two DB messages.
    I agree that Nav produces pretty traffic but NAV also used to avoid it whenever it is possible.
    Proof is: as DenSter Quoted example:
    Check out Codeunit 90:
    Code:
    GetGLSetup()
    IF NOT GLSetupRead THEN
    GLSetup.GET;
    GLSetupRead := TRUE;

    Obviously, boolean variable is the best way.
    If you all agree, maybe they should implement above structure in something like GETCASHED because setup tables (with one row only and read purpose) are pretty frequently used in code(just to save coding).

    Thanks!

    Best Regards,
    Amer
  • sblot
    sblot Member Posts: 21
    For me a get on a setup table is poor in DB traffic.
    When i use the client monitor a GET is less than 1 ms.
    I completly agree with Black tigger

    You just need to do the get before your loop for a get on a setup table.

    But do better attention with the FIND and FINDSET and the keys

    regards.
  • DenSter
    DenSter Member Posts: 8,307
    Oh I do agree that you will not get any real performance increase by modifying one GET statement (unless that GET statement is executed 1000 times in a loop or something).
  • kriki
    kriki Member, Moderator Posts: 9,135
    Or without boolean:
    function GetGLSetup
    IF recGeneralLedgerSetup."Primary Key" = '' THEN BEGIN
      recGeneralLedgerSetup.GET();
      recGeneralLedgerSetup."Primary Key" := 'X';
    END;
    

    of course, you may not save the record.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • ara3n
    ara3n Member Posts: 9,258
    I think the code can be written in 50 different ways. I think standard navision should have a signle instance codeunit so that you get all the setups at logining in of the company and then you could just get them from the single instance codeunit.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n