Get Manager name based an selected user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2019 06:51 AM
Hi team,
i am trying to set Manager field based on the requested for filed both are reference type..
Any help would be appreciated...........
Thanks in advance
Below is the script ::
Client Script :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var userID = g_form.getValue('requested_for');
alert(userID); // it's returning sys_id of the user
var user = new GlideAjax('GetManagerName');
user.addParam('sysparm_name','GetManagerName');
user.addParam('sysparm_requsr',userID);
user.getXML(callbackFunction);
function callbackFunction(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('manager',answer);
}
}
Script Include :
var GetManagerName = Class.create();
GetManagerName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
GetManagerName: function(){
var requsr = this.getParameter('sysparm_requsr');
var req = new GlideRecord('sys_user');
req.addQuery('sys_id',requsr);
req.query();
while(req.next())
{
var mangr = g_form.getValue('manager');
return mangr;
}
},
type: 'GetManagerName'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2019 07:27 AM
Hi Alien,
Thanks for your immediate response,
It's working perfectly on SP Page....
But my Requirement is :
we're trying to set the manager's name on the user's form...we have the same two fields on the user form whenever we change the requested for [reference type] user name on the form it's also change manager's name on the form.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2019 08:10 AM
Good Morning,
You are confusing everyone in this thread. I have given you the correct answer to set the field to the user's manager without using a script include/glideajax. If it's an onChange client script FOR the requested for field...then every time the requested for is changed...it will auto lookup their manager and put it in the manager field.
Please give more information as you have 3 different people helping in this thread and my solution alone is the least complicated and easiest to use.
If you're having to type the same response to all 3 people then you aren't being clear in your post.
Please mark reply as Helpful/Correct. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2019 07:07 AM
You almost had it, there is one small mistake in your script include. Look at the correction i made in the below script.
Script Include : //--> Make sure Client Callable checkbox is checked
var GetManagerName = Class.create();
GetManagerName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
GetManagerName: function(){
var requsr = this.getParameter('sysparm_requsr');
var req = new GlideRecord('sys_user');
req.addQuery('sys_id',requsr);
req.query();
while(req.next())
{
var mangr = req.getValue('manager'); // g_form.getValue('manager');// g_form is a client side entity -> So you shouldnt use in the scriptinclude
return mangr;
}
},
type: 'GetManagerName'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2019 07:16 AM
Hello,
Thanks for the reply..
It's working perfectly on the SP page....
Thank you so much...
But for us we're trying to set the manager's name on the user's form...we have the same two fields on the user form whenever we change the requested for [reference type] user name on the form it's also change manager's name on the form.
Thanks in advance...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2019 07:45 AM
Arjun,
What exactly is the issue? And is the desired functionality.
Thank you,
A.R.G
Note: I don't beg for points.