KB-2120 totalCount returns incorrect results


Users may experience one or more of the following symptoms:

Symptom 1

When querying a database table or view from an expression rule, totalCount shows a different value than the actual number of results. For Example:

Symptom 2

When trying to use query results as data in an a!gridField component, the interface fails to load with an error similar to the below image:

Additionally, the application server log shows an error similar to the following:

A grid component [label=“”] has an invalid value for “totalCount”. “totalCount” must not be null or less than the number of items in any of the “data” arrays, but “totalCount” was 0 and the largest column data array had 8 items. (APNX-1-4198-000)


The field defined in Appian as the primary key maps to a field in the database table or view that is not unique or allows for null values.

totalCount is determined based on the number of unique entries in the primary key field. If the primary key field contains duplicate, non-unique values or null values, totalCount will not match the actual number of result items. 


Update the database table or view to have a unique, non-null primary key, or update the field defined in Appian as the primary key to refer to a unique, non-null field.

Affected Versions

This article applies to all versions of Appian.

Last Reviewed: May 2020