Get the requested for manager details on the form through onload script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 09:20 AM
Hi All,
Having a requirement that need to get the requested for manager details like email id and phone number.
trying with get reference but not getting the empty values.
Any suggestions.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 09:31 AM
Hi @Community Alums ,
Use GlideAjax https://docs.servicenow.com/bundle/vancouver-api-reference/page/script/ajax/topic/p_AJAX.html
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 09:33 AM
Hi,
Try this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ref = g_form.getReference('requested_for', req);
}
function req(ref) {
g_form.setValue('<where you want to save the manager>', ref.manager);
}
}
Run this on change of requested for.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 09:43 AM
we are already having the requested for - manager population on the form.
based on the manager we need to get the manager details like manager email and manager phone number etc,.
Any suggestion.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 01:43 AM - edited 01-05-2024 01:51 AM
For this you need to write a script include and call that from the client side using GlideAjax.
Client Side
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('getManagerDetails');
ga.addParam('sysparm_name', 'getDetails');
ga.addParam('sysparm_requestedFor', g_form.getValue("requested_for"));
ga.getXML(updateFields);
}
function updateFields(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var returneddata = answer.evalJSON(true);
g_form.setValue("<field to populate>", returneddata.name);
g_form.setValue("<field to populate>", returneddata.phone);
g_form.setValue("<field to populate>", returneddata.email);
}
Script include
var getManagerDetails= Class.create();
getManagerDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails: function () {
var requestedFor= this.getParameter('sysparm_requestedFor');
var loc = new GlideRecord('sys_user');
if (loc.get(requestedFor)) {
var json = new JSON();
var results = {
//fetchRequested for's Manager's details
"phone": loc.manager.getValue("phone"),
"email": oc.manager.getValue("email")
"name": oc.manager.getValue("name")
};
return json.encode(results);
}
} else {
return null;
}
}
};