
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2020 08:27 AM
Hello,
I'm trying to setup user criteria based on group type.
On a similar post someone shared this script:
var gr = new GlideRecord('sys_user_group');
gr.addActiveQuery();
gr.addQuery('name', id);
gr.setLimit(1);
gr.query();
if (gr.type == '1cb8ab9bff500200158bffffffffff62')
gr.hasNext();
But I haven't been able to make it work.
Please help
Thank you
Lorenzo
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2020 11:37 PM
Ah oke, now I see your functional question for the first time 🙂 Only saw scripting before.
Try below code. Queries the Group Member table. Group type should be ITIL, user should be dynamic me. If any result: true!
(function() {
var queryStr = 'group.typeLIKE1cb8ab9bff500200158bffffffffff62^userDYNAMIC90d1921e5f510100a9ad2572f2b477fe';
var grGroupMember = new GlideRecord('sys_user_grmember');
grGroupMember.addEncodedQuery(queryStr);
grGroupMember.setLimit(1);
grGroupMember._query();
var answer = false;
if(grGroupMember.hasNext()) {
answer = true;
}
return answer;
})();
= tested!
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2020 12:48 AM
Hi,
In that case you need to change the table to 'sys_user_grmember' in the script above & replace 'type' to 'group.type' which would be something like below.
answer = applyrestriction();
function applyrestriction() {
var id = gs.getUser().getRecord().getValue('name'); //gets name of logged in user
var gr = new GlideRecord('sys_user_grmember');
gr.addActiveQuery();
gr.addQuery('user.name', id);
gr.addQuery('group.type', '1cb8ab9bff500200158bffffffffff62');
gr.setLimit(1);
gr.query();
if(gr.hasNext()) {
return true;
}
return false;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2020 11:37 PM
Ah oke, now I see your functional question for the first time 🙂 Only saw scripting before.
Try below code. Queries the Group Member table. Group type should be ITIL, user should be dynamic me. If any result: true!
(function() {
var queryStr = 'group.typeLIKE1cb8ab9bff500200158bffffffffff62^userDYNAMIC90d1921e5f510100a9ad2572f2b477fe';
var grGroupMember = new GlideRecord('sys_user_grmember');
grGroupMember.addEncodedQuery(queryStr);
grGroupMember.setLimit(1);
grGroupMember._query();
var answer = false;
if(grGroupMember.hasNext()) {
answer = true;
}
return answer;
})();
= tested!
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2020 06:45 AM
Thank you so much Mark,
Your script worked.
I really appreciate your help, I also really appreciate the article you posted below, it's a great resource, it's going in to my bookmarks for sure.
Best
Lorenzo

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 03:53 AM
Awesome! Just what I needed. Thanks how sharing, Mark.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2020 01:11 AM
Hi Lorenzo,
Here's an useful article I wrote a while ago:
Utilizing the breadcrumb on lists to generate your query
With using this, you could set up your queries a lot easier. I also used this for the solution I provided here.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field