The CreatorCon Call for Content is officially open! Get started here.

Not to Show the roles in list collector that are already present in selected group

Preethi26
Tera Contributor

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

Preethi26_0-1701412574694.png

 

2 ACCEPTED SOLUTIONS

@Preethi26

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

@Preethi26 

add this in variable attributes

ref_qual_elements=group;action

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

13 REPLIES 13

Ankur Bawiskar
Tera Patron
Tera Patron

@Preethi26 

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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.

@Preethi26

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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.

Preethi26_0-1701427601543.pngPreethi26_1-1701427624809.pngPreethi26_2-1701427641113.pngPreethi26_3-1701427652920.png

 

@Preethi26 

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.

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader