The CreatorCon Call for Content is officially open! Get started here.

Add 2 Queries to a Before Query Businessrule

MisterSimon
Tera Expert

HI Everybody!

We've been implementing some COE security Policies for our Instances. These work perfectly fine and don't cause any issues.
These COE Hide a lot of Records and most users cannot access them, which causes almost all of our pages to be empty with the statement "Number of rows removed from this list by Security constraints: 100". 

This adds a ton of unnecessary clutter and a lot of empty pages.
To combat this we added a before Query Business rule which adds the currently active COE Security Policy as a Query Parameter and this works most of the time.

 

We've got one special COE Policy which consists out of 2 different Paramenters.

1. (hr_service == Change Personal Data OR hr_service == Change Personal Finance)  && subject_person == Dynamic Me

OR
2. (hr_service == Exit Contract && active == true)

The Idea is that the user can see his own "Personal Data change" and "Personal Finance Change" but also work on ALL "Exit Contracts" even if he isnt directly added as a Subject Person.

This seems to work in the List view, but doesn't in the Portal page. I've found some articles describing this Problem: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0564887

 

Now my Question. Is it Possible to add 2 OR Queries to the before Query Business rule?

Or is there a workaround I haven't found yet?

Thank you for any advice

3 REPLIES 3

TejasSN_LogicX
Tera Contributor

Hi @MisterSimon ,

Yes, it’s definitely possible to add OR conditions in a Before Query Business Rule — but you just have to structure it the right way.

 

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

    var userID = gs.getUserID();
    var encodedQuery =
        'hr_service.name=Change Personal Data^subject_person=' + userID +
        '^ORhr_service.name=Exit Contract^active=true';

    current.addEncodedQuery(encodedQuery);

})(current, previous);

 

TejasSN_LogicX_0-1760621132427.png

 

 

 

If my response helped you, please mark it as the correct answer and close the thread. This way, others in the community can benefit too.

Regards,
TejasSN_LogicX
ServiceNow Developer | HackaNow Finalist | Community Contributor
📧 tejas.adhalrao11@gmail.com
🔗 LinkedIn

 

MisterSimon
Tera Expert

HI @TejasSN_LogicX  
Thanks for your answer
i Should've been a bit more specific. The Problem is the user can access multiple HR Services like "Personal Data change" and "Personal Financing" but only if he's the subject person, but he can access all active "Exit Contracts" regardless if he's the subject Person.

So the queries look something like this

1. (hr_service == Change Personal Data || hr_service == Change Personal Finance)  && subject_person == Dynamic Me

OR
2. (hr_service == Exit Contract && active == true)


So we've got nested OR and AND statements
Sorry for the confusion

Best Regards

Ankur Bawiskar
Tera Patron
Tera Patron

@MisterSimon 

try the approach shared by Tejas

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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