djn
djn

Reputation: 113

Visual studio online Rest Api query- Get results sorted by a field

I am querying visual studio online API to get a list of work items. The result that I get is by default sorted based on the work item ID. I am trying to get the result sorted by TargetedDate field.

Any idea on how to specify the sort column in the rest query?

Thanks in advance...

Upvotes: 1

Views: 912

Answers (2)

DaveShaw
DaveShaw

Reputation: 52798

I think you might have to build a WIQL query using an ID in (1,2,3) filter and execute it.

That way you can specify sorting as ORDER BY TargetDate.

For example:

POST
https://fabrikam.visualstudio.com/DefaultCollection/Fabrikam-Fiber-Git/_apis/wit/wiql?api-version=1.0

Content-Type: application/json

{
  "query": "Select ID From WorkItems Where ID in (1,2,3) ORDER BY TargetDate ASC"
}

More info on the API and WIQL syntax is available on MSDN Docs.


Or....

Just sort it client-side ;)

Upvotes: 4

Eddie Chen - MSFT
Eddie Chen - MSFT

Reputation: 29976

You need to specify the sort column for the query before use it.

From REST API, update it use the WIQL query as DaveShaw mentioned.

From VSO Web Portal, update the settings for the query from "Column options\Sort Columns", add "Target Date" to "Selected Columns" and select the sort type you want. enter image description here

Upvotes: 2

Related Questions