Skip to main content
February 14, 2025
Question

Count the number of records in the data entity

  • February 14, 2025
  • 4 replies
  • 0 views

HI
I'm trying to count the number of records in the data entity HVSDC_PlanesMejoramiento_Entity that meet a specific filter on the field CodigoSIRECISujetodeControl.

This is the SQL query, which works fine:


SELECT CodigoSIRECISujetodeControl, COUNT(NombreAccion) AS total_acciones
FROM HVSC_V_PlanesMejoramiento
WHERE CodigoSIRECISujetodeControl = '11745' 
GROUP BY CodigoSIRECISujetodeControl;

This is the query in Appian:

local!count: a!queryEntity(
entity: cons!HVSDC_PlanesMejoramiento_Entity,
query: a!query(
logicalExpression: a!queryLogicalExpression(
operator: "AND",
filters: {
a!queryFilter(
field: "CodigoSIRECISujetodeControl",
operator: "=",
value: tostring(ri!codigoSireci)
)
}
),



aggregation: a!queryAggregation(
aggregationColumns: {
a!queryAggregationColumn(
field: "NombreAccion",
aggregationFunction: "COUNT"
)
},
groupingColumns: {
a!queryGroupingColumn(field: "CodigoSIRECISujetodeControl")
}
),


pagingInfo: a!pagingInfo(
startIndex: 1,
batchSize: 500
)
)
).data

It throws the following error:

This section contains errorsTest Output

Expression evaluation error at function a!queryEntity: At least one field must be grouped when defining a query with an aggregation.

    4 replies

    andrewh6762
    February 14, 2025

    The field being grouped is referring to having the "isGrouping" variable in the a!queryAggregationColumn() function set to true for at least one field.

    Also, not sure what groupingColumns or the a!queryGroupingColumn() is.

    karumurua531442
    February 15, 2025

    Hi  [mention:5e9bd6a8d413474da290c5dea9da8010:e9ed411860ed4f2ba0265705b8793d05]  could you check this link  and makes changes to your code that might help you to solve the error. 

    docs.appian.com/.../fnc_scripting_a_aggregationfields.html

    mikes0011
    Brainy
    February 15, 2025

    I'm unclear why you're using aggregation if you're merely trying to count the number of records in the view that have a Control Code(?) of 11745.  Unless I'm misunderstanding the shape of your data (which you haven't really specified), you should be able to just do a regular query on the view, a regular Query Filter on the "11745" value, set "fetch total count" as TRUE, then get the TotalCount value included in the resultant DataSubset.

    mathieud0001
    February 16, 2025

    As Mike suggested, all you need is the total count returned by the data subset, you can even set the batchSize to 1 if all you need is the count and you want it to run faster.