- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 05:02 PM
Hello,
I'm attempting to populate my direct reportee text box based on the name in the 'My name' box, but I couldn't get it to work. Can someone identify what is wrong with this script? Thank you.
Client Scripts:
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 05:23 PM - edited 02-08-2024 05:23 PM
Hi @Lisa Goldman there is a error in your script include
getDirectReports: function() {
var directReports = [];
var grUser = new GlideRecord('sys_user');
grUser.addActiveQuery();
grUser.addQuery('sys_id',this.getParameter('sysparm_user')); // need to get user's manager, in this case abraham manager
//grUser.addQuery('manager', this.getParameter('sysparm_user'));
grUser.orderBy('name');
grUser.query();
while (grUser.next()) {
directReports.push(grUser.getDisplayValue('manager'));// get display value of manager
}
return JSON.stringify(directReports);
},
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 07:10 PM
Hi @Lisa Goldman Users will have always a single manager so I have modified your script include and client script as below
Script include:
getDirectReports: function() {
var grUser = new GlideRecord('sys_user');
grUser.addActiveQuery();
grUser.addQuery('sys_id', this.getParameter('sysparm_user'));
grUser.orderBy('name');
grUser.query();
if(grUser.next())
{
if (grUser.manager == '') {
return "";// no manager return blank value
}
else{
return grUser.manager.name.toString();
}
}
},
client script:
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 06:30 PM
Hi @Lisa Goldman could you check alert here and respond back?
function populateDirectReports(answer) {
alert(JSON.stringify(answer,null,4);
if (answer) {
var arr = JSON.parse(answer);
var direct_reports = arr.join("\n");
g_form.setValue('my_direct_reportee_text', direct_reports);
}
else
{
alert("No Manager found");
}
}
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 06:39 PM
We are almost there. Just need a bit of cleaning:
The alert should display: 'No Manager found.'
Instead of this
or

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 07:10 PM
Hi @Lisa Goldman Users will have always a single manager so I have modified your script include and client script as below
Script include:
getDirectReports: function() {
var grUser = new GlideRecord('sys_user');
grUser.addActiveQuery();
grUser.addQuery('sys_id', this.getParameter('sysparm_user'));
grUser.orderBy('name');
grUser.query();
if(grUser.next())
{
if (grUser.manager == '') {
return "";// no manager return blank value
}
else{
return grUser.manager.name.toString();
}
}
},
client script:
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 08:29 PM
Thank you for your time and effort. It's working beautifully.