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:27 AM
In the SI, just try to use gr.getValue("user") instead of var user = gr.user;
Do this across the lines in SI and check once.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2020 11:42 AM
If i give var user = gr.getValue("user"); in the logs it is showing undefined. but if i give var user = gr.user; then it is giving sysid of the user.
and also i changed the last line i.e., return in my script include
return user_rec.name+","+user_rec.email+","+user_rec.location;
in the Alert it is giving,
Alfonso Griglen,alfonso.griglen@example.com,8201c34fac1d55eb36e59da730b7d035
My concern is, why only one user is coming? 4 users has to come. ANd the other thing is i have to split with , and set the values of variables in the MVRS. SO how it is possible?
Regards,
Vijay

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2020 11:44 AM
how many times did you get undefined as its inside the log..
go to sys_user_grmember.list and check if user column is empty for that group for any of the users.
and for json, follow that article link as is and it will work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2020 11:52 AM
only one time, it is getting undefined.
in my on Channge CS,
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
var ans = answer.toString();
var spl = ans.split(',');
alert("name is "+spl[0]); ------- it is giving name of the user like Abel Tuter
g_form.setValue('name',spl[0]);
alert("email is "+spl[1]); ------- it is giving email address
g_form.setValue('email',spl[1]);
But not able to set those values in MVRS fields, record is not getting added in MVRS
Regards,
Vijay

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2020 12:04 PM
Hi,
Modify the code of SI like this and check. In this code,
1. in place of name, email and location on left side of oDet object, ensure you are using actual variable names of name, email and location of MRVS.
2. in return, mention the actual MRVS internal name
groupMembers:function()
{
var ar = [];
var arr = [];
var oDet = {};
var aDet = [];
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
oDet = {
"name": user_rec.name+"",
"email": user_rec.email+"",
"location":user_rec.location+""
};
aDet.push(oDet);
}
return JSON.stringify({"your_multirow_varset": aDet});}
}
Client Script
var answer = response.responseXML.documentElement.getAttribute('answer');
var oDetails = JSON.parse(answer);
g_form.setValue("your_multirow_varset", oDetails);
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP