We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Before query Business Rule should execute for related list

Abhishek Sriva2
Kilo Contributor

Hi There,

I have written Before Query Business Rule on Incident table to sort 'caller_id' field for list view. It is working fine but I want this code should only execute for related list.

For Example: Shorting should only apply to related list records (Problem -> Incident), not to incident table's related list records.

Below are the code:

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

gs.getUser().savePreference('incident.db.order','caller_id');

gs.getUser().savePreference('incident.db.order.direction','ASC');

})(current, previous);

 

I tried with RP.isRelatedList() , but no luck.

Any lead will be appreciated.

Regards,

Abhishek

1 ACCEPTED SOLUTION

Tanaji Patil
Tera Guru

Add this condition to you business rule and then it will run only where incident is used as related list.

JSUtil.notNil(GlideTransaction.get().getPageName()) && !(GlideTransaction.get().getPageName().endsWith("_list")) && gs.tableExists(GlideTransaction.get().getPageName()+"")

 

 

-Tanaji

Please mark reply correct/helpful if applicable

View solution in original post

5 REPLIES 5

Good to know.  Haven't tried this yet.  I always assumed that the sort order of records on a table propagated throughout the instance regardless of view.