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

AutoPopulate the Group member when Group is selected in Catalog item

shubhi211
Tera Guru

Hi,

There is a requirement that in Catalog item there is 2 field 

1. Group name (reference field)

2. Group Members

 

So on selecting any Group Name, then in Group Members field all the available group members should auto populate.

 

**which field Type should be taken for Group member field??post.png

Please help!!

4 ACCEPTED SOLUTIONS

swathisarang98
Giga Sage

Hi @shubhi211 ,

 

You can achieve this through onChange Client script and script include,

Few things to note down

1.make Group member field as list collector,

2.create onchange of Group field.

3.Make script include Client callable

 

Client script:

swathisarang98_1-1709413209873.png

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var sysid = g_form.getValue('group');
    var ga = new GlideAjax('getGroupMemeber');
	ga.addParam('sysparm_name','getGroup');
	ga.addParam('sysparm_id',sysid);
	ga.getXML(getResponse);

}

function getResponse(response){
	var ans = response.responseXML.documentElement.getAttribute('answer').toString();
	alert(ans);
	g_form.setValue('group_members',ans);
}

 

 

Script include:

swathisarang98_0-1709413142163.png

 

var getGroupMemeber = Class.create();
getGroupMemeber.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getGroup: function() {

        var sysID = this.getParameter('sysparm_id');
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('group', sysID);
        var arr = [];
        gr.query();

        while (gr.next()) {
            arr.push(gr.user.toString());
        }
        gs.info('line number 16 ' + arr);
        return arr.toString();
    },



    type: 'getGroupMemeber'
});

 

 

Result:

swathisarang98_2-1709413253041.png

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

View solution in original post

@shubhi211 , For Group Manager field you can use Auto populate feature,

 

swathisarang98_3-1709413459251.png

 

Similarly you can configure for group Email

Result:

swathisarang98_4-1709413639402.png

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

View solution in original post

Hi swathi,

 

In Alert I am getting the sys id of the user and in group members fields the value is not GETTING POPULATED1.png

View solution in original post

@shubhi211 ,what is the type of field (Group member)? and did you reference the list table to sys_user ?

View solution in original post

6 REPLIES 6

swathisarang98
Giga Sage

Hi @shubhi211 ,

 

You can achieve this through onChange Client script and script include,

Few things to note down

1.make Group member field as list collector,

2.create onchange of Group field.

3.Make script include Client callable

 

Client script:

swathisarang98_1-1709413209873.png

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var sysid = g_form.getValue('group');
    var ga = new GlideAjax('getGroupMemeber');
	ga.addParam('sysparm_name','getGroup');
	ga.addParam('sysparm_id',sysid);
	ga.getXML(getResponse);

}

function getResponse(response){
	var ans = response.responseXML.documentElement.getAttribute('answer').toString();
	alert(ans);
	g_form.setValue('group_members',ans);
}

 

 

Script include:

swathisarang98_0-1709413142163.png

 

var getGroupMemeber = Class.create();
getGroupMemeber.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getGroup: function() {

        var sysID = this.getParameter('sysparm_id');
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('group', sysID);
        var arr = [];
        gr.query();

        while (gr.next()) {
            arr.push(gr.user.toString());
        }
        gs.info('line number 16 ' + arr);
        return arr.toString();
    },



    type: 'getGroupMemeber'
});

 

 

Result:

swathisarang98_2-1709413253041.png

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

@shubhi211 , For Group Manager field you can use Auto populate feature,

 

swathisarang98_3-1709413459251.png

 

Similarly you can configure for group Email

Result:

swathisarang98_4-1709413639402.png

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

@shubhi211 , Thanks for marking my answer as helpful. If it helped you in any way please accept the solution so that it will be beneficial to the future readers with the same query

 

Thanks

Hi swathi,

 

In Alert I am getting the sys id of the user and in group members fields the value is not GETTING POPULATED1.png