- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2017 09:11 AM
I'm looking to populate several fields on a catalog item by looking up values on a user record based on their workID#. I've done this successfully for one variable using a catalog client script and a script include. However I don't want to have to create multiple catalog client scripts and script includes and would rather combine it all into 1 of each. I'm having trouble with how to script each for multiple variables. Any help would be great, thanks!
here's the catalog client script, in here you see the 4 variables I want to populate off the user record. IS THIS SCRIPT CORRECT?
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == ''){
g_form.setValue('first_name','');//name of field on form you want to auto populate
g_form.setValue('last_name','');//name of field on form you want to auto populate
g_form.setValue('supervisor','');//name of field on form you want to auto populate
g_form.setValue('emp_location','');//name of field on form you want to auto populate
}
var ga = new GlideAjax('u_employee_details_lookup_Ajax');//name of script include
ga.addParam('sysparm_name', 'getEmployeeDetails');//name of function on script include
ga.addParam('sysparm_user', g_form.getValue('emp_workday_id'));//name of field on form triggering call
ga.getXML(EmployeeDetailsLookup); // Always try to use asynchronous (getXML) calls rather than synchronous (getXMLWait)
}
// Callback function to process the response returned from the server
function EmployeeDetailsLookup(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert('answer: ' + answer);
var answers = answer.split('|');
g_form.setValue('first_name',answers[0]);
g_form.setValue('last_name',answers[1]);
g_form.setValue('supervisor',answers[2]);
g_form.setValue('emp_location',answers[3]);
}
and here is the script include: NOT SURE WHAT TO DO WITH THIS TO ACCOMMODATE FOR THE 4 VARIABLES, I KNOW THIS IS INCOMPLETE.
var u_employee_details_lookup_Ajax = Class.create();
u_employee_details_lookup_Ajax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getEmployeeDetailsfunction(){
var retVal; // Return value
var user = this.getParameter('sysparm_user');
var firstNameRec = new GlideRecord('sys_user');//table where desired variable lives
firstNameRec.addQuery('user_name',user);
firstNameRec.query();
// Query user records
if(firstNameRec.next())
{
retVal = firstNameRec.first_name;//name of field with info you want to grab
}
return retVal;
},
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2017 08:48 AM
Hi Pat,
You can return a string from script include with all value separated by comma.
for example:
retVal = firstNameRec.first_name+','+firstNameRec.last_name+','+firstNameRec.supervisor+','+firstNameRec.emp_location;
And split this string and set the each field values in Client script:(Like below)
var answers = answer.split(',');
g_form.setValue('first_name',answers[0]);
g_form.setValue('last_name',answers[1]);
g_form.setValue('supervisor',answers[2]);
g_form.setValue('emp_location',answers[3]);
Thanks,
Arindam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2018 04:18 AM
Hi Patrcik,
Thanks for sharing your script. Was struggling to pass multiple values until I saw your post.
Cheers to you and Arindam!!
Regards,
DasB

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2018 03:34 AM
Hi, in my case, I've got a problem with filling in the Location variable from the user who has been selected in list collector. using glide ajax, script include, am being given correct value in alert.
The only problem is that the reference Location doesn't want to be populated by the line:
g_form.setValue('location',answer);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2018 11:45 PM
Hi Piotr,
is your alert that shows the "answer" showing a sys_id? Can you provide a screen shot?