Page 1 of 1

How to use Query Case?

PostPosted: Wed Aug 23, 2023 2:57 am
by john1598360627
I want to use the query case to make a ranked sort.

Code: Select all
   query.sort.add(
      query.case
         .when( query.columns.order_status.eq( "APPROVED") ).then( 1 )
         .when( query.columns.order_status.eq( "PENDING") ).then( 2 )
         .when( query.columns.order_status.eq( "WEB") ).then( 3 )
         .when( query.columns.order_status.eq( "TRANSREQ") ).then( 4 )
         .when( query.columns.order_status.eq( "OPEN") ).then( 5 )
         .when( query.columns.order_status.eq( "POSTED") ).then( 6 )
         .when( query.columns.order_status.eq( "RECEIVED") ).then( 7 )
         .else( 8 )
   )


When the query gets loaded into the foundset nothing happens. Am I missing something in how this should be setup?

Re: How to use Query Case?

PostPosted: Wed Aug 23, 2023 9:13 am
by huber
Don't know about query.sort.add, we use it in query.result like

Code: Select all
query.result
   .add(query.case
      .when …

Re: How to use Query Case?

PostPosted: Thu Aug 24, 2023 2:12 am
by john1598360627
huber wrote:Don't know about query.sort.add, we use it in query.result like

Code: Select all
query.result
   .add(query.case
      .when …

Hmm, I'm trying to use sort cus I'm trying to sort the foundset of the grid for display purposes.

I tried result just to see and it didn't work in my scenario.

Re: How to use Query Case?

PostPosted: Thu Aug 24, 2023 2:42 am
by john1598360627
With some testing I tried more stuff and for some reason I could get it to work but only once on the onShow.

Using the onSearchCommand breaks this query sort. No idea why. Seems like a bug.