Query business rule to hide the records

Roxi1
Tera Contributor

here we have ritm records which needs to hide if the user is not part of "IT" team.

we tried to hide through ACL but not working as expected , field are getting hide but not the complete record.

here the ACL for reference:

if(gs.getUser().isMemberOf("IT")){
answer =true;
}

1 ACCEPTED SOLUTION

Hi,

Okay so you want this

1) if user is member of IT then show records where u_hr=true

2) if user is not member of IT then show records where u_hr=false

then update the BR as this

Condition: gs.getSession().isInteractive()

Script:

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

	// Add your code here
	if(gs.getUser().isMemberOf("IT"))
		current.addEncodedQuery("u_hr=true");
	else
		current.addEncodedQuery("u_hr=false");

})(current, previous);

Let me know if I have answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

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

View solution in original post

16 REPLIES 16

Ankur,

I need your help here, I have a similar scenario. Trying to hide a particular request/request item from everyone except a group. So, I created a before query business rule and it hides the records from others.

(function executeRule(current, previous /*null when async*/ ) {
	
    if (gs.getUser().isMemberOf("ABC")) {
        return;
    }
    current.addEncodedQuery("short_descriptionNOT LIKERequest for XYZ");

})(current, previous);

But the issue is while submitting the form. When anyone from "ABC" group, submits the Request for XYZ form, it is creating Request, Request Item - all good.

 

Anyone outside "ABC" group, submits this form, see this. Nothing got created.

Rajini2_1-1687471285325.png

When I added myself to the "ABC" group, order processed correctly.

 

Do you know what is happening? how to fix this?

@Rajini2 

Can you post a new question for this and tag me there?

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