Help needed with accessing multi row variable set in client script

Bruler1230
Tera Expert

sorry for the cross post, this was posted in the developer community as well, I just really need to get some traction on this  

I am using a multi row variable set and I need to autopopulate fields based on what is selected in a reference field within the mrvs. I want to do this by using a onChange catalog client script. It looks like that is a little more complicated to do with multi row variable sets. I have found the below but i am looking for some help on how to implement it. The mrvs allows a user to select a name from the reference field (multiple names, not just the current user) and then based on the name they pick, all the following fields will autopopulate. the user name field is referencing the user table.

Step 1 : Create a script include and write your logic for gathering the data from table and push the data into array of objects. Return the array as return JSON.stringify(array); 

Step 2: In your catalog client script, Write the GlideAjax and call the function in the script include creatd in step 1, In the callback function, write below code :

var answer = response.responseXML.documentElement.getAttribute("answer");
answer = JSON.parse(answer);

g_form.setValue('the  name of the multi row variable list',JSON.stringify(answer));

 

Please let me know if any additional info is needed.

Thanks

 
18 REPLIES 18

Do i need to add a line like this: var name= this.getParameter('sysparm_user_id'); 

for every variable in my variable set? so as an example

var email = this.getParameter('sysparm_u_email');
var phone = this.getParameter('sysparm_u_phone');

Nope this line should be on what variable you want the results??

Let say, for X user name, you need X's email and X's phone.

 


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

my variable set is called user_info and the user name field (u_user_name) is the reference field. 

so a little more info...the picture below shows the multi row variable set that users are filling out. The user name field is a reference field, and all the other fields need to autopopulate when that user name is selected.find_real_file.png

So your script should just send the user_name parameter back to Server and Server would return with UserEmail, UserPhone and userDepartment.

SI:

Client callable

var GetUserDetails = Class.create();

GetUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getDetails: function(){

var retVal ;

var name= this.getParameter('sysparm_u_user_name');//replace accordingly

var gr = new GlideRecord('sys_user');

gr.addQuery('sys_id', name);

gr.query();

if(gr.next())

{

retVal = gr.department.getDisplayValue()+','+gr.email+','+gr.phone; // replace department with your desired field from sys_user table
}

return retVal;

},

type: 'GetUserDetails'

});

CS:

function onChange(control, oldValue, newValue, isLoading) {
var ga = new GlideAjax('GetUserDetails');
ga.addParam('sysparm_name','getDetails');
ga.addParam('sysparm_u_user_name',g_form.getValue('u_user_name'));
ga.getXML(simple);

function simple(response){
var answer = response.responseXML.documentElement.getAttribute('answer');
var a = answer.split(',');
g_form.setValue('emailVariableHere',a[1]);
g_form.setValue('DepartmentVariableHere',a[0]);
g_form.setValue('PhoneVariableHere',a[2]);

}
}

Please mark my response as correct and helpful if it helped solved your question.
-Thanks