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

Naveen Velagapu
Mega Guru

hi Roxi,

Yes , query BR perfectly fits in here. It can filter the data when query is made to db. Here is the sample

 

	if (!gs.getUser().isMemberOf('IT') )
		current.addEncodedQuery('assignment_group.name!=IT')

 

Additional you may include some other conditions such as , if user is admin filter shouldn't work etc.

 

Mark "Helpful / correct answer" if this helps

can we alter the ACL to make work the same requirement?

Swapnil Soni1
Giga Guru

Hello Roxi,

You can do a script within the UI Policy

 

function onCondition() {

var grpName = '205fac11db606b04fe86fd641d9619ff'; //Group SysID
var usrID = g_user.userID;
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('group', grpName);
grp.addQuery('user', usrID);
grp.query(groupMemberCallback);

function groupMemberCallback(grp){



if(grp.next()){

g_form.setVisible('u_conference_call_needed', false); // you can put your item name
g_form.setVisible('u_is_an_escalation_needed', false);

}

}

}

This will hide fields if you did SetVisible .

 

Please make Correct or helpful if this helps!

Thanks

hello sony,

thanks for your reply, but we are not looking to hide fields , but hide the complete record