COUNT Function (RecordRef)
Counts the number of records that are in the filters that are currently applied to the table referred to by the RecordRef.
Number := RecordRef.COUNT
The RecordRef that refers to the table.
Property Value/Return Value
The number of records in the table.
This function returns the number of records that meet the conditions of any filters associated with the records. If no filters are set, the function shows the total number of records in the table.
The COUNT function does not lock the table before it retrieves the number of records in the table. This means that the function reads both uncommitted and committed data, which could cause the number of records that is returned to be inaccurate. To make sure that the count is accurate, use the LOCKTABLE Function (RecordRef) before you use the COUNT function.
In previous versions of Dynamics NAV, the COUNT function ignored security filters and always returned the total number of records unless you called the SETPERMISSIONFILTER function to get a filtered count. In Microsoft Dynamics NAV 2018, the COUNT function adheres to the SecurityFiltering Property. For more information, see Security Filter Modes.
This function works just like the COUNT Function (Record).
The following example opens table number 18 (Customer) as a RecordRef that is named MyRecordRef. The LOCKTABLE Function (RecordRef) locks the table. The COUNT function then retrieves the number of records in the table. The number of records is stored in the Count variable. The name of the table and the number of records in the table is displayed in a message box. The varTableNo variable can be used to open any table and get the number of records in that table by changing the value of the varTableNo variable. This example requires that you create the following variables and text constant in the C/AL Globals window.
|Text constant name||DataType||ENU value|
|Text000||Text||The number of records in the %1 table is: %2.|
varTableNo := 18; MyRecordRef.OPEN(varTableNo); MyRecordRef.LOCKTABLE; Count := MyRecordRef.COUNT; MESSAGE(Text000, MyRecordRef.NAME, Count);