include orderby in query business rule

srikanthvk
Giga Expert

Hi All,

I have been trying to include orderBy in my query business rule and somehow I'm unable to make it work.

Can someone guide if we can use orderBy in the query business rules?

Code Snippet:

var qc = current.addQuery('active','true').orderBy('state');

Thanks,

Srikanth Varma

9 REPLIES 9

SanjivMeher
Kilo Patron
Kilo Patron

Can you check if the method used here works



Adding qualifier in business rule



Please mark this response as correct or helpful if it assisted you with your question.

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Hi Srikanth,



I can't really see the reason why you want to do this. Can you write a bit more about the requirement you have that makes you want to do this?


The requirement is to sort the list on state. We know that a default sort can be applied to the list, the problem with default sort is that it'll be overridden by the user preference. So, I'm looking for a way such that the list is always sorted by state.


Well, sorting it on the query doesn't really help you in this case. You will sort the data and then send it to the user. Then they can sort it for whatever they like to. What you can do is force a system wide setting on that table. This can be done e.g. through a system wide user preference or through arguments on the module the click on. Then you can make a before Business rule on user preference to stop them from setting their own preference on that table. But they will still be able to click around for that specific moment thou. But next time they come to the list, it will be your settings that apply.