i am unable to get the userdetails instead it is return null value.can any one help me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2023 03:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2023 05:53 AM
Your client script should look more like this - with some temporary alerts for troubleshooting:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var abc = g_form.getValue('u_name');
alert("Name = " + abc);
var ga = new GlideAjax('AutoPopulateUserDetails');
ga.addParam('sysparm_name', 'getUserDetails');
ga.addParam('sysparm_usr', abc);
ga.getXML(ResponseFunction);
function ResponseFunction(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert('Answer = ' + answer);
g_form.setValue('u_first_name', answer.split(';')[0]);
g_form.setValue('u_last_name', answer.split(';')[1]);
g_form.setValue('u_manager', answer.split(';')[2]);
g_form.setValue('u_location', answer.split(';')[3]);
g_form.setValue('u_email', answer.split(';')[4]);
}
}
And a couple of changes to the Script Include to use the correct field names, prevent unexpected results returning sys_id and email type fields, and aide in the troubleshooting and a best practice of always returning a value:
var AutoPopulateUserDetails = Class.create();
AutoPopulateUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
type: 'AutoPopulateUserDetails',
getUserDetails: function() {
var answer = 'not found';
var xyz = this.getParameter('sysparm_usr');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', xyz);
gr.query();
if (gr.next()) {
answer = gr.first_name +";" + gr.last_name + ";" + gr.manager.toString() + ";" + gr.location.toString() + ";"+ gr.email.toString();
}
return answer;
},
});
This is assuming your u_manager and u_location fields on the form that you are setting are reference type fields, otherwise use gr.manager.name and gr.location.name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2023 07:06 AM
Let's give the Auto-populate feature a try without a single line of code.
Sample.
Cheers,
Tai Vu