Which query are you running? Can you send a more complete example so I can try to reproduce it here?
Post
Followmultiple order by in query possible?
Should I be able to order by multiple fields in a query?
If I run the following and exchange the order of ord1,ord2 in orderBy = New OrderBy() {ord2, ord1}, the query always sorts the same; using createdon
Dim orderBy As OrderBy()
Dim ord1 As New OrderBy
ord1.FieldName = "State"
ord1.OrderSpecified = True
ord1.Order = Order.Descending
Dim ord2 As New OrderBy
ord2.FieldName = "CreatedOn"
ord2.OrderSpecified = True
ord2.Order = Order.Descending
orderBy = New OrderBy() {ord2, ord1}
query.Orders = orderBy
Please sign in to leave a comment.
3 comments
Date
Votes
I removed the where clause and my processing code where is says 'do something here
TypeName is Case, or Issue, or EnahancementRequest
Order by are valid clarizen field names for the corresponding entity type
Dim incidentlist As New ArrayList
Dim query As EntityQuery = New EntityQuery()
query.TypeName = TypeName
query.Fields = Entity.SplitList(Issue.BaseQueryFields)
If SortDir <> "" AndAlso SortField <> "" Then
Dim orderBy As OrderBy()
Dim ord1 As New OrderBy
ord1.FieldName = SortField
ord1.OrderSpecified = True
If SortDir = "Ascending" Then
ord1.Order = Order.Ascending
Else
ord1.Order = Order.Descending
End If
orderBy = New OrderBy() {ord1}
query.Orders = orderBy
Else
Dim orderBy As OrderBy()
Dim ord1 As New OrderBy
ord1.FieldName = "State"
ord1.OrderSpecified = True
ord1.Order = Order.Descending
Dim ord2 As New OrderBy
ord2.FieldName = "CreatedOn"
ord2.OrderSpecified = True
ord2.Order = Order.Descending
orderBy = New OrderBy() {ord2, ord1}
query.Orders = orderBy
End If
Dim qr As QueryResult = client.Query(query)
'only want first 100 rows for test query
If qr.Success Then
For Each IssueEntity As GenericEntity In qr.Entities
'do something here
Next
End If
Return (incidentlist)
Hi Roxy.
I've tried your code on my account and the sorting seems to be working OK. When I changed the order the sorting was changed accordingly.
You may have noticed:
With the code you've sent the first field on the sort list IS CreatedOn.
The CreatedOn field values contains the time. So sorting by CreatedOn and another field will probably be the same as sorting by CreatedOn only.
If you review your code and the results and you can't find the reason, please E-mail me at ophir.kenig@clarizen.com
Ophir