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

Parameters

  • RecordRef
    Type: RecordRef The RecordRef that refers to the table.

Property Value/Return Value

Type: Integer

The number of records in the table.

Remarks

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.

Note

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 Microsoft 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 2013 R2, the COUNT function adheres to the SecurityFiltering Property. For more information, see Security Filter Modes.

This function works just like the COUNT Function (Record).

Example

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.

Variable name DataType

MyRecordRef

RecordRef

Count

Integer

varTableNo

Integer

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);

See Also

Reference

RecordRef Data Type