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 11:50 AM
Hi,
Try below code
In Script include
var mvrs = Class.create();
mvrs.prototype = Object.extendsObject(AbstractAjaxProcessor, {
groupMembers:function()
{
var something = this.getParameter('sysparm_details');
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group',something);
gr.query();
var result =
{
name:" ",
email:" ",
location:" "
};
while(gr.next())
{
var user = gr.user;
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
result.name:user_rec.name;
result.email:user_rec.email;
result.location:user_rec.location.getDisplayValue();
}; //user while close
return JSON.stringify(result);
} //grmember while is closed
},//groupMembers function is close
type: 'mvrs'
});
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);
var res = JSON.parse(answer);
g_form.setValue('field_name',res.name);
g_form.setValue('field_name',res.email);
g_form.setValue('field_name',res.location);
}
}
I hope it will help you.
Please Mark Correct/Helpful answer if it help you in any way.
Thanks,
Kunal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2020 12:15 PM
Hi Kunal,
in these 3 lines,
result.name:user_rec.name;
result.email:user_rec.email;
result.location:user_rec.location.getDisplayValue();
it is showing errors.
i have modified my SI and on CHange CS
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;
gs.log("user is "+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");
var name = user_rec.name;
var email = user_rec.email;
var location = user_rec.location;
gs.log("User details "+name+" "+email+" "+location);
arr.push(name+" "+email+" "+location);
}
return user_rec.name+","+user_rec.email+","+user_rec.location;
}
},
type: 'mvrs'
});
.........................................................................
CS:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var arra = [];
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);
var ans = answer.toString();
var spl = ans.split(',');
g_form.setValue('testing_populations',JSON.stringify(spl[0]));
}
}
.........................................................................................................
in the alert it is showing
and to set the value in a MVRS, g_form.setValue('testing_populations',JSON.stringify(spl[0]));
here testing_populations is my variable set name. Not understanding how to set the name, email and location coming in alert to the variables in MRVS.
Also, there are 4 members in the selected group but why only one user is coming in my alert? Anything wrong in my SI?
Regards
VIjay

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2020 12:54 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2021 06:48 AM
Hello Vijay,
Did you get any solution for this? I have similar requirement.
Thanks in advance