Populate the members of the group in a variable Dynamically.

Insider
Giga Guru

Hello Everyone,

 

I am trying to auto populate members of the groups in a variable based on other variable choices.

EX: We have 2 variable V1 and V2

 

V1 has 3 choices

Choices: TYPE1, TYPE2, TYPE3.

This Variable and the choices are not dependent to the V2 groups.

 

When V1 is selected as = TYPE1

the Variable V2 should show the list of group members who are part of  group "Group1"

 

When V1 is selected as = TYPE2

the Variable V2 should show the list of group members who are part of  group "Group2"

 

When V1 is selected as = TYPE3

the Variable V2 should show list group members who are part of group "Group 3"

 

Please help me with this functionality.

5 REPLIES 5

maroon_byte
Mega Sage

You will need to create a client callable script include which will:

1. Accept type (from V1) as the parameter

2. Return returns comma-separated sys_ids of the members of the group by quering sys_user_grmember.

3. The variable V2 will be a reference variable on sys_user

4. In the V2's Reference qualifier, need to have code such as below:

javascript:'active=true^sys_idIN' + new YOURSCRIPTINCLUDENAME.YOURFUNCTIONNAME(current.variables.v1name);

Hello Maroon,

 

Can you help me with the script please?

In your client callable AJAX script include:
getMemberIDs: function(valueV1) {
        if (valueV1 == '')
            valueV1 = this.getParameter('sysparm_valueV1') + '';
 
if (valueV1 == 'TYPE1')
grp = <SYS ID of Group1>;
else if (valueV1 == 'TYPE2')
grp = <SYS ID of Group2>;
else if (valueV1 == 'TYPE3')
grp = <SYS ID of Group3>;
 
        var memberSysIDs = [];
        var memgr = new GlideRecord('sys_user_grmember');
        memgr.addQuery('group', grp);
        memgr.query();
        while (memgr.next()) {
            memberSysIDs.push(memgr.user.sys_id.toString());
        }
        return memberSysIDs.toString();
    },
 
Usage: In your Variable Variable V2:
javascript&colon;'active=true^sys_idIN' + YOURSCRIPTINCLUDENAME().getMemberIDs(current.variables.V1VarialbeName);

 

Hello,

 

I tried this but i got many syntax errors. I just pasted the same.