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.

Populate user names depending upon the selected group name

Bijay Kumar Sha
Giga Guru

I've a catalog item which contains a variable 'Select Governance Group' which is a 'reference' type and which is referred to a custom table "u_rlm_governance_group". 

I've an another variable 'Name of members to be removed from Governance Group' which is a 'list collector' type. 

My requirement is to above variable should contains all the user names depending upon 'Select Governance Group' reference group. If I change the 'Select Governance Group' name, then user names available should be updated in 'Name of members to be removed from Governance Group' variable. 

How I can achieve this?

3 REPLIES 3

Murthy Ch
Giga Sage

Hello @Bijay Kumar Sha 

In "Name of members to be removed from Governance Group" variable currently all user's are populating in it or it's just a filter?

Thanks,
Murthy

Hi @Murthy Ch , currently in the reference qualifier, I've referenced it to the user table only which is showing all the user names. 
But I want above variable should contains all the user names depending upon 'Select Governance Group' reference group. If I change the 'Select Governance Group' name, then user names available should be updated in 'Name of members to be removed from Governance Group' variable. 

Runjay Patel
Giga Sage

Hi @Bijay Kumar Sha ,

 

You can do the following.

1. Create one script include to get the list of member based on selected group.

listOfMember: function() {
        var group= this.getParameter('sysparm_group');

        var grpMember= [];
        var grMem = new GlideRecord('Table name of your group and user mapping');
        grMem .addQuery('group', group);
        grMem .query();
        while (grMem .next()) {
			
            grpMember.push(grMem .sys_id.toString());
        }
        return grpMember.toString();
    },

 

2. Create catalog onchange client script 

if (isLoading) {
        return;
    }

    if (newValue === '') {
        g_form.clearValue('your variable name'); 
    }

    var ga = new GlideAjax('getGRPMem');
    ga.addParam('sysparm_name', 'listOfMember');
    ga.addParam('sysparm_group', newValue);
    ga.getXML(populateValues);

    function populateValues(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
 		g_form.setValue('your variable name);
    }

 

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------