- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2019 07:03 AM
Hi,
below code works perfect and returns manager sysid if run for users with ITIL license. However, it's returning undefined for normal end users. Any ideas? Thanks.
I'm trying to run this on client script if user selects a requestor, his manager name should write to console for now.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var usr = g_form.getReference('requestor',callBack);
function callBack(usr){
console.log ("hello2:" + usr.manager);
g_form.setValue('requestor_manager',usr.manager);
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2019 06:48 AM
@Allen : It worked on the portal for end users who have ITIL license and not for other users. They will always access this form through portal to request a service.
Hi,
I tried all the suggested combinations and it still didnt work. To make this work, I'm utilizing one of our existing script includes and called it using glideAjax. Surprisingly, this worked without tweaking any ACLs for the user record.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// var usr = g_form.getReference('requestor',callBack);
var ga = new GlideAjax('getUserManager');
ga.addParam("sysparm_name", "getonBehalfOfManager");
ga.addParam("sysparm_user", g_form.getValue('requestor'));
ga.getXML(getResponse);
function getResponse(response) {
var values = response.responseXML.documentElement.getAttribute('answer').toString().split('||');
g_form.setValue('requestor_manager', values[1]);
}
}
/*function callBack(usr){
console.log ("hello: " + usr.manager);
g_form.setValue('requestor_manager',usr.manager.toString());
} */
Here is my code on the script include:
var getUserManager = Class.create();
getUserManager.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getonBehalfOfManager : function(){
var group = this.getParameter('sysparm_user');
var rel = new GlideRecord("sys_user");
rel.addQuery("sys_id", group);
rel.query();
var name_arr = [];
var sys_id_arr = [];
if(rel.next())
{
name_arr.push(rel.manager.name.toString());
sys_id_arr.push(rel.manager.toString());
}
return name_arr.toString() + '||' + sys_id_arr.toString();
},
type: 'getUserManager'
});
Regards,
Krishna

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2019 07:14 AM
Try below :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var usr = g_form.getReference('requestor',callBack);
}
function callBack(usr){
console.log ("hello2:" + usr.manager);
g_form.setValue('requestor_manager',usr.manager);
}
Regards,
Sanket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2019 07:42 AM
Hello Sanket,
I'm sorry, I failed to notice any changes to the code you posted vs mine.
Regards,
krishna

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2019 07:44 AM
Hi,
He closed out the initial function...and opened the callback outside of it...
It'd be recommended to copy and paste the code, since you have your old code here.
Please mark reply as Helpful, if it was. 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
09-17-2019 07:59 AM
Thank you @Allen.
Hello Sanket,
Still no luck! It works fine (your code / my code) if user has ITIL access. Doesn't work for normal end users with no roles.
Regards,
krishna