- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 11:46 AM
When the group variable is selected all the members of the selected group should auto-populate.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 11:32 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 11:55 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 02:03 PM
Hi @Kishor O ,
You can write a script include and call that script include from Catalog client script as shown below ,
Catalog Client script :
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 :
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 10:12 PM
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 11:32 PM
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