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

Ali Shaikh1
Giga Expert

Hi,

Please go through the link which is usefull.

Click Here

Community Alums
Not applicable

Hi Abhishek,

The method above you have used will apply to any list view whether related or not for incident. If you want a sorted related list on Problem, you should create a relationship table where you can query and orderby.

 

Applies to table: Problem

Queries: Incident

 

Relationship record

find_real_file.png

Problem Record with ordered related list:

 find_real_file.png

 

Note how the related list is ordered by newest to oldest without having filtered the related list.

Please mark as solved/helpful if this has worked for you.

Thanks,

Enrique

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

please check below links:

https://community.servicenow.com/community?id=community_question&sys_id=06dd745adba4db0058dcf4621f96...

https://community.servicenow.com/community?id=community_question&sys_id=0a914f33db9813000e58fb651f96...

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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