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

How does the before Business Rule on User Preference work? I've tried setting it and nothing happens so when users change the sort order it is a permanent change for them.

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Try something like this:



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


qc.orderBy('state');


I tried this but no luck.


Is at least the list coming back with Active=True?


gourav786gs
Tera Contributor

Though it is an old query but to help community further I would like to add some of my suggestion, 

1. Do check that whether any already sorting is happening on your list view or not.
2. In my case I was experiencing same issue, later I checked that whenever I am opening my incident list, it already doing some sorting which you can also confirm from the URL: "incident_list.do%3Fsysparm_filter_pinned%3Dtrue%26sysparm_query%3D^ORDERBYDESCsys_updated_on".
3. Here above my incident list already sorted by updated on that was the reason the query br for order by was not working!

4. So you can try just "your-instance.com/incident_list.do".
5. Hope this will work.


QUERY BR SCRIPT - 


current.addQuery('assigned_to', gs.getUserID());

    current.orderByDesc('priority');