You are currently reviewing an older revision of this page.

DRAFT KB-[SP-3142] totalCount returns incorrect results

Symptoms

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 when:

  • batchSize is not set to -1
  • fetchTotalCount is true

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:

Additionally, the application server log shows and 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)

Cause

There are two possible causes for this issue:

  1. The primary key for the database table or view is not unique or allows for null values.
  2. The database table or view does not use the same field for the primary key as the corresponding CDT.

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. 

Action

  1. Ensure the database table or view and corresponding CDT use the same field for the primary key.
  2. Update the affected table or view to have a unique, non-null primary key.

Affected Versions

This article applies to all versions of Appian.

Last Reviewed: May 2020