Show group member in list collector based on another variable from sys_group

Jeck Manalo
Tera Guru

Hi,

 

How can we filter the list of user in list collector based on what is selected to another variable,

 

variable 1 = group

variable 2 = goal is to show list of member only based on selected in variable 1.

 

In my mind I need to use onchange and script include.

 

I saw this post that are sample to populate in reference qualifier : Solved: How to show only users from respective group in re... - ServiceNow Community

 

I applying this concept but I try to add onchange to pass the value of sysid of the group into script include so in reference qualifier will display members.

 

script include:

JeckManalo_0-1759373483169.png

 

but not its not working.

 

Anythoughts how to show member of the group in catalog using onchange/script include/reference qualifier ?

 

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@Jeck Manalo 

Since you want to filter i.e. restrict users no script include required, do this

1) 2nd variable list collector should refer to sys_user

2) 1st variable should be reference type pointing to sys_user_group

3) use this advanced ref qualifier

4) Ensure you give correct variable name in below script and variable attributes

javascript: var query;
var arr = [];
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", current.variables.groupVariable);
gr.query();
while (gr.next()) {
   arr.push(gr.getValue('user'));
}
query = 'sys_idIN' + arr.toString();
query;

4) give this in variable attributes of 2nd variable

ref_qual_elements=groupVariable

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

mayankkumar
Kilo Patron
Kilo Patron

@Jeck Manalo,
If you still want to go with script include approach 
try this
1. Modify you script include, refer image

mayankkumar_0-1759378814682.png

2. On your List collector variable, Use reference qualifier like this ->

mayankkumar_1-1759378884994.png

(Make sure to adjust the variable name)
This way you can call your script include directly in the reference qualifier, no need to use onChange client script and no need to make your script include GlideAjax enabled

Outcome ->

mayankkumar_2-1759379139670.png

-------------------------------------------------------------------------------------------------------------------------------------------
Please mark my response helpful and accept as solution
Thanks & Regards
Mayank

 

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@Jeck Manalo 

Since you want to filter i.e. restrict users no script include required, do this

1) 2nd variable list collector should refer to sys_user

2) 1st variable should be reference type pointing to sys_user_group

3) use this advanced ref qualifier

4) Ensure you give correct variable name in below script and variable attributes

javascript: var query;
var arr = [];
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", current.variables.groupVariable);
gr.query();
while (gr.next()) {
   arr.push(gr.getValue('user'));
}
query = 'sys_idIN' + arr.toString();
query;

4) give this in variable attributes of 2nd variable

ref_qual_elements=groupVariable

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,

 

In my understanding,

 

for #4 input this code to variable = sys_user_group ref qualifier.

 

while #5 input in variable attributes in = sys_user.

 

I tried that but nothing works, i input correct variable.

 

mayankkumar
Kilo Patron
Kilo Patron

@Jeck Manalo,
If you still want to go with script include approach 
try this
1. Modify you script include, refer image

mayankkumar_0-1759378814682.png

2. On your List collector variable, Use reference qualifier like this ->

mayankkumar_1-1759378884994.png

(Make sure to adjust the variable name)
This way you can call your script include directly in the reference qualifier, no need to use onChange client script and no need to make your script include GlideAjax enabled

Outcome ->

mayankkumar_2-1759379139670.png

-------------------------------------------------------------------------------------------------------------------------------------------
Please mark my response helpful and accept as solution
Thanks & Regards
Mayank

 

@Jeck Manalo, try this one and if you still need any help, please let me know

Although, I think @Ankur Bawiskar approach should also works

This works perfectly. 

Thank you for your help I appreciate.