Why use the GET function with setup tables?

alex6789alex6789 Member Posts: 9
Why does the get function need to be used in this instance:

if not SalesReceivableSetup.get() then
SalesReceivableSetup.insert();

if SalesReceivableSetup."Order Nos." = ' ' then begin
SalesReceivableSetup."Order Nos." := CreateNoSeries();
SalesReceivableSetup.Modify();



Best Answers

  • rasmuwerasmuwe Member Posts: 4
    Answer ✓
    The statement "if not get" checks that if a record cannot be found in the setup table then it will create a new empty record (.insert). Then no matter what we know that we have fetched a record in the lines further down where we set the "Order Nos." field and modify the record. Either we have gotten (GET) the existing record in the setup table or we have created (INSERT) a new record in the table.
  • PascualPascual Member Posts: 9
    Answer ✓
    Hi alex6789,

    Why is it necessary to use the get function in this case?

    If you don't do a GET, you don't position yourself on any records in the table, so you don't actually modify any values.

    The GET in tables with a primary key of a single field is the equivalent of doing as many SETRANGE as fields have the primary key of other tables such as number 37, which you are doing in another part of the code.


    SalesLine.SETRANGE("Document Type","Document Type");
    SalesLine.SETRANGE("Document No.","Document No.");
    SalesLine.SETRANGE("Attached to Line No.","Line No.");
  • RockWithNAVRockWithNAV Member Posts: 1,139
    Answer ✓
    @alex6789 - That's something which also gazed my attention during my initial days, Get is used to when you want to filter directly on Primary key Value OR else we use SETRANGE. For all these setup tables we have just one record and the name of the Primary key column is Primary Key only.

    By default if you will se these setup pages there's code written to check if its not blank then simply INIT INSERT, which ia actually inserting one record whose primary key value is something NULL you can say,

    So that's why we simply GET which nothing as parameter and then it gets the reference for the entire columns.

Answers

  • rasmuwerasmuwe Member Posts: 4
    Answer ✓
    The statement "if not get" checks that if a record cannot be found in the setup table then it will create a new empty record (.insert). Then no matter what we know that we have fetched a record in the lines further down where we set the "Order Nos." field and modify the record. Either we have gotten (GET) the existing record in the setup table or we have created (INSERT) a new record in the table.
  • PascualPascual Member Posts: 9
    Answer ✓
    Hi alex6789,

    Why is it necessary to use the get function in this case?

    If you don't do a GET, you don't position yourself on any records in the table, so you don't actually modify any values.

    The GET in tables with a primary key of a single field is the equivalent of doing as many SETRANGE as fields have the primary key of other tables such as number 37, which you are doing in another part of the code.


    SalesLine.SETRANGE("Document Type","Document Type");
    SalesLine.SETRANGE("Document No.","Document No.");
    SalesLine.SETRANGE("Attached to Line No.","Line No.");
  • RockWithNAVRockWithNAV Member Posts: 1,139
    Answer ✓
    @alex6789 - That's something which also gazed my attention during my initial days, Get is used to when you want to filter directly on Primary key Value OR else we use SETRANGE. For all these setup tables we have just one record and the name of the Primary key column is Primary Key only.

    By default if you will se these setup pages there's code written to check if its not blank then simply INIT INSERT, which ia actually inserting one record whose primary key value is something NULL you can say,

    So that's why we simply GET which nothing as parameter and then it gets the reference for the entire columns.
Sign In or Register to comment.