RecordRef.Count() Method

Version: Available or changed with runtime version 1.0.

Counts the number of records that are in the filters that are currently applied to the table referred to by the RecordRef.

Syntax

Number :=   RecordRef.Count()

Note

This method can be invoked using property access syntax.

Parameters

RecordRef
 Type: RecordRef
An instance of the RecordRef data type.

Return Value

Number
 Type: Integer
The number of records in the table.

Remarks

This method returns the number of records that meet the conditions of any filters associated with the records. If no filters are set, the method shows the total number of records in the table.

Note

The Count method does not lock the table before it retrieves the number of records in the table. This means that the method 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 Method (RecordRef) before you use the Count method.

In previous versions of Dynamics 365, the Count method ignored security filters and always returned the total number of records unless you called the SetPermissionFilter method to get a filtered count.

This method works just like the Count Method (Record).

Example

The following example opens table number 18 (Customer) as a RecordRef that is named MyRecordRef. The LockTable Method (RecordRef) locks the table. The Count method 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.

var
    MyRecordRef: RecordRef;
    varTableNo: Integer;
    Count: Integer;
    Text000: Label 'The number of records in the %1 table is: %2.';
begin
    varTableNo := 18;  
    MyRecordRef.Open(varTableNo);  
    MyRecordRef.LockTable;  
    Count := MyRecordRef.Count;  
    Message(Text000, MyRecordRef.Name, Count);  
end;

See Also

RecordRef Data Type
Get Started with AL
Developing Extensions