How to set value of Group members based on group in Catalog form

Kishor O
Tera Sage

KishorO_0-1707767043197.png

When the group variable is selected all the members of the selected group should auto-populate.

 

1 ACCEPTED SOLUTION

Hi @Kishor O ,

 

In script include replace return member.join("\n"); with return members.toString();

 

and in Client script replace g_form.setValue('group_member',answer); with g_form.setValue('group_member',answer.toString());

 

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

Regards,

Swathi Sarang

 

 

View solution in original post

4 REPLIES 4

Sumanth16
Kilo Patron
Hi Kishor,


Please check below links, same question is already answered and you can adopt the script include logic to get users based on group selected.

https://community.servicenow.com/community?id=community_question&sys_id=f303339cdbc6b340feb1a851ca96...

https://community.servicenow.com/community?id=community_question&sys_id=148ce6dddbf45c90190dfb243996...



Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.

Thanks & Regards,
Sumanth Meda

swathisarang98
Giga Sage
Giga Sage

Hi @Kishor O ,

You can write a script include and call that script include from Catalog client script as shown below ,

 

Catalog Client script :

swathisarang98_0-1707775164008.png

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
var ga = new GlideAjax('GetGroupInfo'); //Gliding to script include 
    ga.addParam('sysparm_name', 'getMembers');//gliding to Function
    ga.addParam('sysparm_group', newValue); //passing the group name
    ga.getXMLAnswer(setGroupMembers);

    function setGroupMembers(answer) {
		alert(answer);
        g_form.setValue('group_member',answer); // replace group_members with actual variable name
    }
   
}

 

Script Include :

swathisarang98_1-1707775228773.png

 

var GetGroupInfo = Class.create();
GetGroupInfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getMembers: function() {
        var members = [];
        var group = this.getParameter("sysparm_group");
        var grUser = new GlideRecord("sys_user_grmember");
        grUser.addQuery("group", group); 
        grUser.query();
        while(grUser.next()){    
           members.push(grUser.user.user_name.toString());
        }
        return members.join("\n");
    },

    type: 'GetGroupInfo'
});

 

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

Regards,

Swathi Sarang

 

 

@swathisarang98  I am unable to set all the values returned from the array ,only the first element of the array is setting in the list collector field. How to set all the elements from the array to list collector field

Hi @Kishor O ,

 

In script include replace return member.join("\n"); with return members.toString();

 

and in Client script replace g_form.setValue('group_member',answer); with g_form.setValue('group_member',answer.toString());

 

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

Regards,

Swathi Sarang