Force Related List sort order in ServiceNow

Force Related List sort order in ServiceNow

Have you ever wanted to force a related list in ServiceNow to sort by a particular field, disregarding the default sort and any custom user sort changes?

Well boy do I have a treat for you!

Not only is it effective, but its also much simpler than you would expect.

Say you wanted to force sort a list by the Order field Ascending, how would you do it I hear you ask? Well, feast your eyes!!

Create an onBefore query business rule on the table in question and insert the following script.

(function executeRule(current, previous /*null when async*/) {

	var query = "ORDERBYorder";
	current.addEncodedQuery(query);

})(current, previous);
onBefore query business rule

How about Descending? Almost identical, just add DESC.

(function executeRule(current, previous /*null when async*/) {

	var query = "ORDERBYDESCorder";
	current.addEncodedQuery(query);

})(current, previous);
onBefore query business rule

You're welcome! ;)