Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How restrict particular RITM records using Query Business Rule

Aparna Gurav
Tera Contributor

Hello Team, 

 

I want to hide particular RITMs created from the specific catalog item using the Query Business rule for all users and it shows visible to only specific Groups

 

I created a Business rule But it's not working as expected, Still, non-specified group members see that RITM

 

AparnaGurav_0-1683115038689.png

 

AparnaGurav_1-1683115096329.png

 

1 ACCEPTED SOLUTION

Try this

 

 

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

if (!(gs.getUser().isMemberOf('7547606d879e4d1080bba8a90cbb3595') || gs.getUser().isMemberOf('2dd2fa7f87922d50a4a486e40cbb3589'))) {

current.addEncodedQuery('cat_item!=858476ff87922d50a4a486e40cbb3571');
}


})(current, previous);

 

Also, once you get the script working, try to avoid the hardcoded sys_id

 

-Anurag

View solution in original post

8 REPLIES 8

Try this

 

 

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

if (!(gs.getUser().isMemberOf('7547606d879e4d1080bba8a90cbb3595') || gs.getUser().isMemberOf('2dd2fa7f87922d50a4a486e40cbb3589'))) {

current.addEncodedQuery('cat_item!=858476ff87922d50a4a486e40cbb3571');
}


})(current, previous);

 

Also, once you get the script working, try to avoid the hardcoded sys_id

 

-Anurag

I don't know why but this not working for me is it something OOB ACL that we need to modify?

 

Hello Aparna,

Change the code like below and try.

 

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

// Add your code here
if ((!gs.getUser().isMemberOf('7547606d879e4d1080bba8a90cbb3595')) && (!gs.getUser().isMemberOf('2dd2fa7f87922d50a4a486e40cbb3589'))) {

current.addEncodedQuery('cat_item!=858476ff87922d50a4a486e40cbb3571');
}


})(current, previous);

 

Regards,

Devender

rupalipati
Tera Contributor

When I write a before Query business rule on RITM record then it stops the RITM record creation as well