Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Filter Glide list field values based on other Glide List values

Venkata Sunil K
Tera Contributor

Hi all,

I have a requirement where I have 2 Glide list in the form. Lets say for an example:

  1. Group - Type - Glide list (Reference to Group)
  2. Users - Type - Glide list (Reference to User)

Under each group, we have multiple users.

Group-A

Group-B

Group-C

User-1

User-4

User-7

User-2

User-5

User-8

User-3

User-6

User-9

 

I used an advanced reference qualifier in the user dictionary, which is working if I select a single value in a group. But If I select multiple groups, both groups users are not visible in the user Glide list.

If I select 2 groups, both the group users should be visible in the user Glide list.

Can any one help?

Thanks!



8 REPLIES 8

Murthy Ch
Giga Sage

Hi @Venkata Sunil K 
You can use below logic for your requirement. Just now tested in my instance and it is working as expected.

 

javascript: new global.NVS_IT_AdvancereturnRoles().filterusersbyGroup(current.u_assignment);  //replace with your function name and field name

MurthyCh_0-1668155204482.png

 

//server side script

filterusersbyGroup: function(group) {
        var arrM = [];
        var grR = new GlideRecord("sys_user_grmember");
        grR.addQuery("group", "IN", group.toString());
        grR.query();
        while (grR.next()) {
            arrM.push(grR.getValue("user"));
        }
        return "sys_idIN" + arrM.toString();

    },

 

(=tested)

Hope it helps:)

 

 

Thanks,
Murthy

Hi Murthy, thanks for your assistance!

I tried the logic as you suggested but its not working.

 

Script Inlude:

myFunction: function(caseType) {
var arrM = [];
var grR = new GlideRecord("sn_hr_core_case_sub_type");
grR.addQuery("u_case_type", "IN", u_case_type.toString());
grR.query();
while (grR.next()) {
arrM.push(grR.getValue("u_name"));
}
return "sys_idIN" + arrM.toString();

},

 

Advanced Reference Qualifier: 

javascript: new myScriptInclude().myFunction(current.case_type);

 

I'm missing something here?

Hi @Venkata Sunil K 

Update the line like below and try:

 

grR.addQuery("u_case_type", "IN", caseType.toString());

If still not works keep some logs in while loop and post the results here.

 

 

Thanks,
Murthy

Ankur Bawiskar
Tera Patron
Tera Patron

@Venkata Sunil K 

your script and your example are different

what's your actual requirement here? to show users based on group selected or related to HR?

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