- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2023 06:28 AM
Hi All,
Maybe someone out there help me to debug this small script in User Criteria.
I created a User Criteria script to determine if a user is a member of any group whose name starts with the prefix ‘IT Support’, and although it works fine in Scripts-background by returning true is the logged in user is a member of a group starting with 'IT Support...', , it fails to do so when implemented in the User Criteria.
I am not sure if there is a better way to implement it, or if I am missing something, When I impersonate a member of one of any 'IT Support...' group, it fails to show the catalog item for them.
Name: Group Names Starting with IT Support
---------------------------------------------------------
IsAnITSupportMember();
//To grant access to this catalog item to members of any group whose name starts with 'IT Support'.
function IsAnITSupportMember() {
var loggedInUser = gs.getUserID();
var user_Rec = new GlideRecord('sys_user_grmember');
user_Rec.addQuery("sys_id", loggedInUser); // it also fails when using "user.sys_id"
user_Rec.addQuery("group.name", "STARTSWITH", "IT Support"); // It also fails when using "group"
user_Rec.setLimit(1);
user_Rec.query();
if (user_Rec.next())
return true;
else
return false;
}
}
---------------------------------------------------------
Thanks,
Juan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2023 06:23 AM
You can try something like this
var member = new GlideRecord('sys_user_grmember');
member.addQuery('user', user_id);
member.addEncodedQuery('group.nameLIKEIT Support');
member.setLimit(1);
member.query();
answer = member.hasNext();
Note: sometimes with new user criterias you might need to logout/login and clear the cache before testing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2023 06:39 AM
Best way is to just add all of the groups to the Groups field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2023 06:12 AM
Thank Mike for your prompt reply.
I had it that way, but I was then asked to do dynamically, so that when a new 'IT Support...' group is created, we do not have to enter the group manually.
Thanks,
Juan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2023 06:23 AM
You can try something like this
var member = new GlideRecord('sys_user_grmember');
member.addQuery('user', user_id);
member.addEncodedQuery('group.nameLIKEIT Support');
member.setLimit(1);
member.query();
answer = member.hasNext();
Note: sometimes with new user criterias you might need to logout/login and clear the cache before testing.
