- 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
‎12-01-2023 12:22 AM
Are you handling removing roles from selected group in same catalog item as well? I think you have 2 actions Add roles and Remove roles?
you can use advanced ref qualifier and add this logic
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 12:54 AM
Yes @Ankur Bawiskar Using same catalog item to add and remove
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: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 02:48 AM
Hi @Ankur Bawiskar Thank You.
I have 2 variables one for Add role and other for remove role.
I have called script include from both variables, its working fine for remove.
But for add its again showing same ad remove.
PFA and kindly correct me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2023 02:54 AM
small update, you didn't copy this line correctly which I shared
it should be NOT IN and not NOTIN
query = 'sys_idNOT IN' + arr.toString();
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