- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 08:48 AM - edited 03-14-2023 08:50 AM
Hi All,
I need to populate user's details on catalog item of logged in user as well as when requested for changes.
fields are - requested for, email, phone, manager, manager phone, manager email.
Note: I have added default values in variable for logged in user details.
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 09:29 AM
Client script
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var reqFor = g_form.getValue('requested_for');//replace with your variable backend value
var ajax = new GlideAjax('insert_ur_script_include_name_here');
ajax.addParam('sysparm_name','getUserData');
ajax.addParam('sysparm_userData', reqFor );
ajax.getXML(calBck);
function calBck(response){
var answer = response.responseXML.documentElement.getAttribute('answer');
var userObj = JSON.parse(answer);
g_form.setValue('field_name1',userObj.propertynameofemail);//email var backend val
g_form.setValue('field_name2',userObj.propertynameofphone);/phone var backend val
//u can add more variables & access via their property names
}
}
Script Include: Make sure to check the client callable checkbox
getUserData: function() {
var userId = this.getParameter('sysparm_userData');
var grUser = new GlideRecord('sys_user');
grUser.get(userId);
var uObj = {
"propertynameofemail" : grUser.getValue('email'),
"propertynameofphone" : grUser.getValue('phone'),
//add other entries similarly
}
return JSON.stringify(uObj);
},
Let me know if this helps!
Thanks,
Nikita Kale
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 10:36 AM
Glad to help!
Please close the thread by marking the appropriate response as correct so that it benefits future readers.
Regards,
Nikita Kale
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 05:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 05:31 AM
Nothing is getting populated, there is an error saying - There is a JavaScript error in your browser console.
When I console, it is Unhandled exception in GlideAjax.
Thanks in advance for help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 05:56 AM
I am using default values like following:
User : javascript:gs.getUserID();
Email: javascript:gs.getUser().getEmail();
Manager: javascript: var manager; var user = new GlideRecord('sys_user'); user.get(gs.getUserID()); manager = user.manager; manager;
Please mark the answer helpful/correct if it solved your query
Regards
Twinkle
You can try Script include for the
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 06:00 AM
Also this question has been previously solved. Below is the link.
Please mark the answer helpful/correct if it solved your query
Regards
Twinkle