user query Business Rule - how to filter results out if [Internal Integrated User] is false

Ore-Jon
Tera Contributor

Hi. I'm looking to apply a filter so that non-admins are not able to use the user accounts where [Internal Integration User] is true. I found the oob 'user query' business rule on the sys_user table where the condition is to filter out any inactive users unless you are admins. But I'm not sure how to also apply a filter for the additional field as well. 

1 ACCEPTED SOLUTION

Chaitanya ILCR
Kilo Patron

Hi @Ore-Jon ,

 

couple of ways you can achieve this

1. you can create one more query BR on User table without touching the OOB one

ChaitanyaILCR_0-1752022580645.png

ChaitanyaILCR_1-1752022587086.png

script

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

    // Add your code here
    if (!gs.hasRole('admin'))
        current.addQuery('internal_integration_user', false);

})(current, previous);

in case you want to show the internal_integration_user= false users to user_admin roled users too

you can update the script as this

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

    // Add your code here
    if (!gs.hasRole(['admin', 'user_admin']))
        current.addQuery('internal_integration_user', false);

})(current, previous);

OR

2. The OOB query User BR looks for users without admin or user_admin role you have to remove the user_admin role condition on the condition if you just want to show 

ChaitanyaILCR_2-1752022870589.png

if your okay show internal integration users to the user_admin roled users update script as below

ChaitanyaILCR_3-1752023023080.png

 

current.addActiveQuery();
current.addQuery('internal_integration_user', false);

 

 

Better go with the first option

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

 

 

View solution in original post

3 REPLIES 3

Community Alums
Not applicable

hi @Ore-Jon ,

Open the existing User Query Business Rule and in the script part, you’ll see logic like:

if (!gs.hasRole('admin')) {
current.addQuery('active', true);
}

 

To add your new filter, you can extend it like this:\

 

if (!gs.hasRole('admin')) {
current.addQuery('active', true);
current.addQuery('internal_integration_user', '!=', true);
}

 

 

Here, 'internal_integration_user' should be the exact name of your field (check the dictionary name on the sys_user table – it might be something like u_internal_integration_user if it’s a custom field).

Chaitanya ILCR
Kilo Patron

Hi @Ore-Jon ,

 

couple of ways you can achieve this

1. you can create one more query BR on User table without touching the OOB one

ChaitanyaILCR_0-1752022580645.png

ChaitanyaILCR_1-1752022587086.png

script

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

    // Add your code here
    if (!gs.hasRole('admin'))
        current.addQuery('internal_integration_user', false);

})(current, previous);

in case you want to show the internal_integration_user= false users to user_admin roled users too

you can update the script as this

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

    // Add your code here
    if (!gs.hasRole(['admin', 'user_admin']))
        current.addQuery('internal_integration_user', false);

})(current, previous);

OR

2. The OOB query User BR looks for users without admin or user_admin role you have to remove the user_admin role condition on the condition if you just want to show 

ChaitanyaILCR_2-1752022870589.png

if your okay show internal integration users to the user_admin roled users update script as below

ChaitanyaILCR_3-1752023023080.png

 

current.addActiveQuery();
current.addQuery('internal_integration_user', false);

 

 

Better go with the first option

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Ore-Jon 

@Chaitanya ILCR already shared both the approaches.

Please use and let us know the feedback

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