User Criteria

Milind1
Tera Contributor

My requirement is to restrict visibility of catalog based on the group. We want dynamic script so that only *SDM groups can see that items. any lead will be helpful 

1 ACCEPTED SOLUTION

Vishal Birajdar
Giga Sage

Hello Milind,

You can try this code in script part of User criteria :

 

/** Scripted User Criteria is not cached, and evaluated everytime, so performance is dependent on the script.
* Populate `answer` with true/false or evaluate to true/false
* The script is evaluated in the scope the user criteria is defined
* Don't use `current` in the script or populate the variable
* Don't use `gs.getUser()` or `gs.getUserID()`,
* instead use `user_id` which contains the user sys_id against whom the evaluation is happening.
*/

answer = isUserMember(user_id);
function isUserMember(user_id) {
var isMember = false;
var gpMember = new GlideRecord("sys_user_grmember");
gpMember.addEncodedQuery('group.nameLIKESDM^user=' + user_id);
gpMember.query();
if (gpMember.next()) {
isMember = true;
}

return isMember;
}

 

VishalBirajdar7_0-1677163173234.png

 

 

You can check this using 'User Criteria Diagnostics'

 

VishalBirajdar7_1-1677163297717.png

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

5 REPLIES 5

Milind1
Tera Contributor

Thanks 

It is working perfectly fine