- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 08-01-2022 04:12 AM
I have explained how to return multiple values from the script include and pass it to the client side.
====================CLIENT SCRIPT======================
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// if (isLoading || newValue === '') {
// return;
// }
//Type appropriate comment here, and begin script below
var ga1 = new GlideAjax('FetchUserDetails');
ga1.addParam('sysparm_name', 'getData');
ga1.addParam('sysparm_user', newValue);
ga1.getXMLAnswer(setDetails);
function setDetails(response) {
var pVal = JSON.parse(response);
g_form.setValue('u_manager', pVal.manager);
g_form.setValue('u_user_s_location', pVal.location);
g_form.setValue('u_mobile_number', pVal.mobile_number);
g_form.setValue('u_username', pVal.username);
g_form.setValue('u_email', pVal.email);
}
}
====================SCRIPT INCLUDE======================
var FetchUserDetails = Class.create();
FetchUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getData: function() {
var user = this.getParameter('sysparm_user');
var obj = {};
var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id', user);
usr.query();
if (usr.next()) {
obj.manager = usr.manager.getDisplayValue();
obj.location = usr.location.getDisplayValue();
obj.mobile_number = usr.mobile_phone.getDisplayValue();
obj.username = usr.user_name.getDisplayValue();
obj.email = usr.email.getDisplayValue();
}
return JSON.stringify(obj);
},
type: 'FetchUserDetails'
});
If you have any feedback related to the scripting part, please write it in the comment box.
- 1,504 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello,
Thanks for posting an article and sharing your knowledge.
There's been a good amount of coverage on this topic. I see you've also commented out the onChange function and isLoading, etc. lines of the client script?
In any case, just to mention this for those looking, if you're working with Catalogs and Variables, then you'd want to utilize the Catalog Lookup Definition feature instead of scripting, if at all possible.
Additionally, as a side note, I wouldn't recommend using another forum account to mark your other content as helpful, correct, bookmark, etc. that is known as "points boosting" and is a violation of the Community forum guidelines. Please don't do that.
Take care!
-Allen
