Populate User Details in Multi Row Variable Set on change of Group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2020 10:47 AM
Hello Guys,
I have created a catalog item with a Group field (reference) and there is a multi row variable set with 3 variables in it. My requirement is, when i select any group in the Group field, then the members of that selected group must auto populate in that Multi row variable set. HOw can i do this?
i have seen this link but the code is little confused to my understanding. Can some one help me here?
Regards,
Vijay

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2020 10:53 AM
you will have to use GlideAjax to return members of group and then use below video to add rows in variable set
https://www.youtube.com/watch?v=JZ341t0iVtY
Regards,
sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2020 11:03 AM
Hello Vijay,
You need to write onChange client script and pass your group field to the SI.
In SI, once you capture that group field, then you see a code which reads mytable. in place of that put the table sys_user_grmember and capture the details of the user. In place of columns mention the name of your columns that you want to show in the MRVS from group member table.
When pushing the values inside the object oDet, the left side columsn shoudl be the name of your variables in the MRVS.
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2020 11:15 AM
Hi Asif,
Happy Ramzan,
I have written Script Include and onChange client script
SI:
var mvrs = Class.create();
mvrs.prototype = Object.extendsObject(AbstractAjaxProcessor, {
groupMembers:function()
{
var ar = [];
var arr = [];
var something = this.getParameter('sysparm_details');
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group',something);
gr.query();
while(gr.next())
{
var user = gr.user;
ar.push(user.toString());
var user_rec = new GlideRecord('sys_user');
user_rec.addQuery('sys_id',user);
user_rec.query();
while(user_rec.next()){
gs.log("inside second while"); ------------------ this is coming in log
var name = user_rec.name;
var email = user_rec.email;
var location = user_rec.location;
gs.log("User details "+name+" "+email+" "+location); ------ this is coming like, User details Alfonso Griglen alfonso.griglen@example.com 8201c34fac1d55eb36e59da730b7d035
(always this only coming, but 4 members are there in that group)
arr.push(name+" "+email+" "+location);
}
return sys_idIN+arr;
}
},
type: 'mvrs'
});
.................................................................................
on Change Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('mvrs');
ga.addParam('sysparm_name', 'groupMembers');
ga.addParam('sysparm_details',newValue);
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer); }
}
.................................................................................
Here, when i run the code, ALert is showing Null and one more thing is, i have kept log messages in SI. Please look into my SI.
Can you help me here plz
Regards,
Vijay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2020 11:25 AM
Beacuse in my MVRS, there are 3 variables, name location and email. So i am thinking that i can populate them with g_form.setValue in the client script. Is that the right way i think?
Regards,
Vijay