How to see if a record is empty?
jensthomsen
Member Posts: 173
Is it possible to check if a record- variable isn't empty? This is what I want to do:
Record.GET(som primary key value);
The check would return TRUE here, since we have a record.
CLEAR(Record);
The ckeck should now return FALSE, since the record-pointer points to "no-where"...
Record.GET(som primary key value);
The check would return TRUE here, since we have a record.
CLEAR(Record);
The ckeck should now return FALSE, since the record-pointer points to "no-where"...
0
Comments
-
IF MyRecord.GET(PrimaryKeyValue) THEN MESSAGE('the record exists') ELSE MESSAGE('the record does not exist');If you do MyRecord.GET on a record that doesn't exist, you will get a runtime error.0 -
Maybe the ISEMPTY-function?
From help:
ISEMPTY (Record)
Use this function to find out whether a C/SIDE table or a filtered set of records is empty.
Empty := Record.ISEMPTY
Record
Data type: record
Refers to the table or the filtered set of records to be checked.
Empty
Data type: boolean
Comments
This function tells you whether the table is empty or not if you have not applied filters to the record. If you have applied filters, the function determines whether the filtered set of records is empty.
The number of filters that you have applied to the records affects the speed of the ISEMPTY function. The fewer the number of filters, the faster the system performs the operation.
When you are using SQL Server, this function is faster than using the Record.COUNT function and then testing the result for zero.
Tino Ruijs
Microsoft Dynamics NAV specialist0 -
1) Record.GET without parameter returns a record with empty primary key which is possible and is used for various setup tables (those tables that hold one record of data)
2) your record variable Record may hold outdated values both for primary key (table record got deleted or renamed by someone) and for other field (someone modified your current record)
one thing you could do to update your information is to reget your record
Record.GET(Record."Primary Key Field(s)")0 -
jensthomsen wrote:Is it possible to check if a record- variable isn't empty? This is what I want to do:
Record.GET(som primary key value);
The check would return TRUE here, since we have a record.
CLEAR(Record);
The ckeck should now return FALSE, since the record-pointer points to "no-where"...
For me main question is "Why you need that"?0 -
kine wrote:jensthomsen wrote:Is it possible to check if a record- variable isn't empty? This is what I want to do:
Record.GET(som primary key value);
The check would return TRUE here, since we have a record.
CLEAR(Record);
The ckeck should now return FALSE, since the record-pointer points to "no-where"...
For me main question is "Why you need that"?
I want to prevent to many database calls: For example a setup table is being used many places. If the table have been read once from the database, theres no need to read it again....0 -
Hi
What do you mean with "points to no-where" ?
Your initial question was "if a record is empty".
BR Per0 -
jensthomsen wrote:I want to prevent to many database calls: For example a setup table is being used many places. If the table have been read once from the database, theres no need to read it again....
I don't think a couple of extra recSetup.GET(); will influence the performance of the database.
Off course it's important you place the recSetup.GET(); in the right place. Not for example in a repeat-until-loop.
Tino Ruijs
Microsoft Dynamics NAV specialist0 -
Setup reading optimalization is done in standard codeunits ant tables through special function e.g.:
GetGLSetup() IF NOT GLSetupRead THEN BEGIN GLSetup.GET; IF GLSetup."Additional Reporting Currency" <> '' THEN BEGIN Currency.GET(GLSetup."Additional Reporting Currency"); Currency.TESTFIELD("Unit-Amount Rounding Precision"); Currency.TESTFIELD("Amount Rounding Precision"); END; END; GLSetupRead := TRUE;
It means that special global variable GLSetupRead is used to flag if the setup was read or not. You can use SingleInstance codeunit with such a function which will return the record as a parameter to read the setup table just once in one session (but it means that when you change the setup, you need to restart the client to have new setup) and call that codeunit's function everywhere in code when you need to get the setup...0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 328 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions


