How to use Query Case?

Find out how to get things done with Servoy. Post how YOU get things done with Servoy

How to use Query Case?

Postby john1598360627 » Wed Aug 23, 2023 2:57 am

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?
john1598360627
 
Posts: 175
Joined: Tue Aug 25, 2020 3:03 pm

Re: How to use Query Case?

Postby huber » Wed Aug 23, 2023 9:13 am

Don't know about query.sort.add, we use it in query.result like

Code: Select all
query.result
   .add(query.case
      .when …
Robert Huber
7r AG, Switzerland
SAN Developer
http://www.seven-r.ch
User avatar
huber
 
Posts: 518
Joined: Mon May 14, 2012 11:31 pm

Re: How to use Query Case?

Postby john1598360627 » Thu Aug 24, 2023 2:12 am

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.
john1598360627
 
Posts: 175
Joined: Tue Aug 25, 2020 3:03 pm

Re: How to use Query Case?

Postby john1598360627 » Thu Aug 24, 2023 2:42 am

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.
john1598360627
 
Posts: 175
Joined: Tue Aug 25, 2020 3:03 pm


Return to How To

Who is online

Users browsing this forum: No registered users and 34 guests