How to use a before query business rule to hide records if certain catalog item

Blair5
Tera Guru

I have a requirement to hide an RITM from one catalog request for everyone unless they are the submitter. Additionally, task needs to be hidden to everyone except users in a particular assignment group or the submitter. 

I was going down the ACL path, but since this is such a small use case, I'd rather use an on before query business rule. Any help appreciated!

1 ACCEPTED SOLUTION

@Blair Reinhart 

In query BR you won't know the RITM's catalog item name using the current object

It will add generic query.

In the case of ACL you will have to create new one and update the existing ones so that they don't work for your catalog item.

But note they will be able to see other RITMs belonging to other catalog item as per your requirement.

Example:

1) New ACL

Condition: Catalog Item [IS] Your Catalog item && Request.Requested For [IS] Dynamic Me

find_real_file.png

2) Older ACLs update

Condition: Catalog Item [IS NOT] Your Catalog item

find_real_file.png

Regards
Ankur

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

View solution in original post

9 REPLIES 9

@Blair Reinhart 

In query BR you won't know the RITM's catalog item name using the current object

It will add generic query.

In the case of ACL you will have to create new one and update the existing ones so that they don't work for your catalog item.

But note they will be able to see other RITMs belonging to other catalog item as per your requirement.

Example:

1) New ACL

Condition: Catalog Item [IS] Your Catalog item && Request.Requested For [IS] Dynamic Me

find_real_file.png

2) Older ACLs update

Condition: Catalog Item [IS NOT] Your Catalog item

find_real_file.png

Regards
Ankur

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

Hey Ankur ! I have the same requirement and I tried to achieve through Before Query Business Rule .The access to requested item and task worked but It is effecting Approvals.Approvals are not getting created when users with not access to the item are submitting request 

Was bit late but Glad you got it working.

As Ankur said getting Item name will not be possible for Business Query rule to work & if so will involve more efforts & thus suggested ACL approach.

Good to know you went for ACL approach & it worked. Welcome to the community.

 

Community Alums
Not applicable

Ankur Bawiskar, 

Can you please help me with before query business rule,

Q: Assets owned by SRG must be hidden from users assigned to a command code outside of SRG.

*Update script to check for Command Code.Parent Command Code IS NOT srg (System Property created as part of this requirement)

Script:

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

// Add your code here

if (current.u_command_code.u_parent_command_code != gs.getProperty('srg')) {
if (!gs.hasRole('srg' || 'admin') && gs.isInteractive()&& gs.getSession()) {
var uID = gs.getUserID();
var uGR = new GlideRecord('sys_user');
uGR.get(uID);
//var q = current.addEncodedQuery('department!=221f3db56112284009f4becd3039cc9');
var a = current.addEncodedQuery('u_command_code.u_parent_command_code!=bf47f29cdb701c10adc48c923996190f'+ gs.getUserName());
uGR.query();
gs.info('srg assets');


}
}


})(current, previous);

 Please help me with this script ,

 Thanks in Advance!

Any help is appreciated from others too!

Daniel Oderbolz
Kilo Sage

This requirement can be fixed with a before query business rule.

See here: https://www.servicenow.com/community/developer-articles/how-to-bypass-query-business-rule-for-catalo...


If this answer was helpful, I would appreciate if you marked it as such - thanks!

Best
Daniel