Post

2 followers Follow
0
Avatar

multiple 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

Import from old forum Answered

Please sign in to leave a comment.

3 comments

0
Avatar

Which query are you running? Can you send a more complete example so I can try to reproduce it here?

Clarizen Team 0 votes
Comment actions Permalink
0
Avatar

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)

Import from old forum 0 votes
Comment actions Permalink
0
Avatar

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:

  1. With the code you've sent the first field on the sort list  IS CreatedOn.

  2. 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

Clarizen Team 0 votes
Comment actions Permalink