Reputation: 339
How do I get the total count of results when paging with the query.v1
endpoint?
A request like this:
/rest-1.v1/Data/Member?page=2,0
returns the following:
<Assets total="4" pageSize="2" pageStart="0">...
Note the attribute total="4"
.
Whereas a query like this:
{
"from": "Story",
"page":
{
"start":0,
"size":2
}
}
returns the following:
[
[
{
"_oid": "Story:1007"
},
{
"_oid": "Story:1015"
}
]
]
Note the lack of any total count.
Is there possibly some special parameter I can provide in the select statement to include the count? (Similar to @Count
with the rest-1.v1/Data
endpoint?)
Upvotes: 1
Views: 696
Reputation: 339
@LaureanoRemedi answered the question but I wanted to expand on it to accommodate filtering Workitems
by more than just Scope
.
Say, for example, we wanted to count the number of tasks belonging to a Story. We can use the down-cast-and-filter syntax to filter Task
s belonging to that Scope
by their Parent
attribute:
"Workitems:Task[Parent='Story:1007'].@Count"
With that, we can build a multi-query request:
[{
"from": "Scope",
"where": {"ID":"Scope:1000"},
"select": [ "Workitems:Task[Parent='Story:1007'].@Count" ]
},
{
"from": "Task",
"where": { "Parent": "Story:1007" }
}]
That returns the count as well as the results:
[
[
{
"_oid": "Scope:1000",
"Workitems:Task[Parent='Story:1007'].@Count": "2"
}
],
[
{
"_oid": "Task:1008"
},
{
"_oid": "Task:1009"
}
]
]
Upvotes: 0
Reputation: 61
After further investigation, here is a solution to count results using two queries:
[
{
"from": "Scope",
"select":["Workitems:Story[AssetState!='Dead'].@Count"],
"filter":["ID='Scope:0'"]
},
{
"from": "Story",
"select": ["Name"],
"filter":["Scope='Scope:0'","AssetState!='Dead'"],
"page":
{
"start":0,
"size":200
}
}
]
Some clarification on line 4:
"select":["Workitems:Story[AssetState!='Dead'].@Count"]
After "Workitems" we are down-casting the collection to "Story", and then filtering where the "AssetState" isn't "Dead" to get active stories and finally counting Workitems.
Here you will find some references and extra documentation:
Upvotes: 1
Reputation: 61
Unfortunately this information is not by default present when using query.v1 endpoint, as it is with rest-1.v1. But here is a workaround you could use, with a two query approach.
[
{
"from": "Scope",
"select":["Workitems.@Count"],
"filter":["ID='Scope:0'","Workitems.AssetType='Story'"]
},
{
"from": "Story",
"select": ["Name"],
"filter":["Scope='Scope:0'"],
"page":
{
"start":0,
"size":2
}
}
]
Upvotes: 1