Count Operator
How to use the Count operator
As the name describes, the Count operator performs a count and returns the total of the count as a number
primitive.
Count operator
The following example illustrates a query that could be used in a workflow to send an email when the number of jobs is greater than 10.
You can also add an And logical operator with an Equals conditional operator related to the task status, this allows you to refine the query.
{
"type": "Query",
"properties": {
"collectionCode": ["Live"],
"dodiCode": "designInterfaces_jobs"
},
"children": [
{
"type": "GreaterThan",
"children": [
{
"type": "Count",
"children": [
{
"type": "ItemProperty",
"properties": {
"itemPropertyName": "itemId"
}
}
]
},
{
"type": "Number",
"properties": {
"value": [10]
}
}
]
}
]
}
The item level count can also be used in expressions with the result compared against the attribute value on the same item rather than against hard coded values as shown above.
Example Use Case
As an example, we can consider a query where we want to fetch the title and subtitle of all projects that are over capacity (which is held in the capacity attribute on the project design). The query below looks for all projects that have a number of tasks greater than or equal to their capacity, contained in a custom attribute attributes_projectsCapacity_60464441c14e5d000ad7e47
.
{
"type": "Query",
"properties": {
"attributes": ["attributes_itemsTitle", "attributes_itemsSubtitle"],
"collectionCode": ["Live"],
"dodiCode": "designs_projects"
},
"children": [
{
"type": "GreaterThan",
"properties": {
"inclusive": true
},
"children": [
{
"type": "Count",
"properties": {
"groupBy": "attributes_projectsTasks"
}
},
{
"type": "Attribute",
"properties": {
"attributeCode": "attributes_projectsCapacity_60464441c14e5d000ad7e479"
}
}
]
}
]
}