KB-1121 Changing the batch size of a!queryEntity also changes the total count

Symptoms

When using a!queryEntity() within an expression, there is a discrepancy between the total count when using an infinite batch size (-1) versus a non-infinite batch size.

For example, here is an a!pagingInfo with an infinite batch size:

local!pagingInfo: 
  if( isnull(ri!pagingInfo),
    a!pagingInfo( startIndex: 1 , batchSize: -1),
    ri!pagingInfo
  )

The above returns a totalCount of 3:

[startIndex=1, batchSize=-1, sort=[field=name, ascending=true], totalCount=3, data=[id:1, name:Bob]; [id:2, name:Jane]; [id:2, name:Joe],  identifiers=1,2,2]

Change the batch size to 3:

local!pagingInfo: 
  if( isnull(ri!pagingInfo),
    a!pagingInfo( startIndex: 1 , batchSize: 3),
    ri!pagingInfo
  )

The above returns a totalCount of 2:

[startIndex=1, batchSize=-1, sort=[field=name, ascending=true], totalCount=2, data=[id:1, name:Bob]; [id:2, name:Jane]; [id:2, name:Joe],  identifiers=1,2,2]

Cause

The column used as the identifier has duplicate values. This is generally bad database design and is not recommended by Appian Technical Support.

In the example above, identifiers contains [1,2,2]. When batch size of -1 is used, totalCount is 3 since it returns the total number of values. When a batch size of anything besides -1 is used, it returns the unique number of values, and since 2 appears twice, the totalCount is 2.

Action

To find the column with duplicates:

  1. Run the expression in Interface Designer.
  2. Look at the identifiers parameter of the expression output. There will be duplicate values within this parameter.
  3. To determine which column is associated to the values being used by the identifiers, copy and find one of the values from the identifiers parameter in the data parameter of the expression output.

Enforce uniqueness on the column that is being used by the identifiers parameter. Consult with your DBA about adding a primary key to that column if one doesn't already exist.

Affected Versions

This article applies to all versions of Appian.

Last Reviewed: February 2017

Related
Recommended