Extra Before Query Business Rule does not grant access for a custom role

mfhaciahmetoglu
Mega Sage

Hello ServiceNow Community,

 

I am trying to implement a customization in a best-practice way by avoiding the modification of an out-of-the-box (OOTB) Business Rule. I've encountered an issue where my new Business Rule seems to be ignored.

 

My goal is to allow a specific custom role, inactive_user_viewer, to view all users on the sys_user table, including those who are inactive.

 

Here is my approach:

  1. I have not modified the OOTB Business Rule named "user query." It is still active with its default logic.

  2. I created a new before query Business Rule on the sys_user table. I set its Order to 110 to ensure it runs after the OOTB rule (which has an order of 100).

My expectation was that my new rule, running later in the order, would override the OOTB filter for users with my custom role. However, the OOTB rule's filter is still being applied, and users with the inactive_user_viewer role cannot see inactive users.

 

Could you please provide some insights into why this setup might not be working? Is there a reason a second before-query rule cannot effectively override the query created by a previous one?

 

Here are the details of my configuration:

OOTB "user query" Business Rule (Active):

  • Table: sys_user

  • Order: 10,000

  • Condition: gs.getSession().isInteractive() && !(gs.hasRole("admin") || gs.hasRole("user_admin"))

  • Script: (Default OOTB script that adds the active=true filter)

My New Business Rule:

  • Name: Custom BR

  • Table: sys_user

  • Order: inactive_user_viewer

  • Condition: !(gs.hasRole("inactive_user_viewer"))

  • Script: (Default OOTB script that adds the active=true filter)

I would appreciate any guidance on how to properly implement this solution while adhering to best practices and not modifying the OOTB rule.

 

Thanks a lot!

 

Best,

Firat

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@mfhaciahmetoglu 

both the business rules will run and append the query and the queries will be combined, so inactive users are still not visible.

Approach 1

-> You need to modify the OOTB query business rule so that it doesn't run for your role user and keep your other query BR

gs.getSession().isInteractive() &&
!(gs.hasRole("admin") || gs.hasRole("user_admin") || gs.hasRole("inactive_user_viewer"))

OR

Approach 2

-> Deactivate the OOTB one and handle everything in your query BR the OOTB logic and your new logic

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@mfhaciahmetoglu 

both the business rules will run and append the query and the queries will be combined, so inactive users are still not visible.

Approach 1

-> You need to modify the OOTB query business rule so that it doesn't run for your role user and keep your other query BR

gs.getSession().isInteractive() &&
!(gs.hasRole("admin") || gs.hasRole("user_admin") || gs.hasRole("inactive_user_viewer"))

OR

Approach 2

-> Deactivate the OOTB one and handle everything in your query BR the OOTB logic and your new logic

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi Ankur, thank you for your reply.

 

If the query is appended, I have the same query (inactive=false) for both business rules, it should just then work for the new BR, no? I only changed the condition and added a new one !gs.hasRole("inactive_user_viewer")) . 

 

Best,

Firat

@mfhaciahmetoglu 

the OOTB query is active=true so it gets appended with your Query BR condition.

I already shared the 2 approaches.

Please discuss with your Architect and Customer and accordingly proceed.

I believe I have answered your question.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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