- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 10:37 PM
Hi Team,
I have created catalog request to add roles to groups.
Now, i want to not show the roles that are already in selected group.
Example if group Next gen already has itil role, so i should restrict it in list collector from user selection to avaoid redundant addition.
Kindly help
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 01:34 AM
then use this in advanced ref qualifier and add this in variable attributes
ref_qual_elements=group
I assume the roles variable refer to sys_user_role table
javascript: var query;
var arr = [];
var option = current.variables.action; // give correct action variable name here
var gr = new GlideRecord("sys_group_has_role");
gr.addQuery("group", current.variables.group); // give correct group variable name here
gr.query();
while (gr.next()) {
arr.push(gr.getValue('role'));
}
if(option == 'add_role') // give correct choice value to compare
query = 'sys_idNOT IN' + arr.toString();
else
query = 'sys_idIN' + arr.toString();
query;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 03:08 AM
add this in variable attributes
ref_qual_elements=group;action
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 11:47 PM
@Preethi26 add reference qualifier and pass current selected group. you have to use script include to check existing roles for that group and pass list of roles which are not present.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 11:51 PM
Hi @Preethi26 ,
You can use below script i have tried in my pdi
I am hard coding the sys_id of group so you have to pass group sys_id from reference qualifier to script include and return roles from script include like "sys_id IN" + rolesToExclude.join(',');
var selectedGroup = '075911922ffe751056a7c786f699b62b';
var usersInGroup = new GlideRecord('sys_user_grmember');
usersInGroup.addQuery('group', selectedGroup);
usersInGroup.query();
var userIDs = [];
while (usersInGroup.next()) {
userIDs.push(usersInGroup.user.toString());
}
var rolesAssigned = new GlideRecord('sys_user_has_role');
rolesAssigned.addQuery('user', 'IN', userIDs);
rolesAssigned.query();
var rolesToExclude = [];
while (rolesAssigned.next()) {
rolesToExclude.push(rolesAssigned.role.getDisplayValue());
}
gs.print(rolesToExclude);
Please mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 12:53 AM
Hi @Anand Kumar P Thank You.
Guess this script will return roles of selected user..
My doubt is... if in catalog item we have 2 variables. "Group" and "Roles to be Added"
So if group AAA has itil role already in it,
In "roles to be added" variable itil role should not be visible for selection.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 01:15 AM
Hi @Preethi26 ,
Above script i am passing group sysid and getting users in that group pushing it to array and getting all users roles.
In your case pass group sysid from reference qualifier and in script include use script i have added get all users roles in that group while returning to reference qualifier you can use sysid not in that roles so you will get roles not in that group and show in list collector.
Thanks,
Anand