How to use Query Case?

I want to use the query case to make a ranked sort.

	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?

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

query.result
	.add(query.case
		.when …

huber:
Don’t know about query.sort.add, we use it in query.result like

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.

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.