How to Display users who report to a specific manager by selecting the manager's name?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 10:53 PM
How to Display users who report to a specific manager by selecting the manager's name?
Scenario:
- Create a Variable (manager ) Reference field and one more variable multiple line text field
- When user enters manager It should fetch all the users reporting to the selected manager in multiline text field.
Please help me on this .
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 11:53 PM
Hi @Ramanjaneyuv,
You can use List Collector variable as a better alternative to multi line text. You need to add a Client Script and use Glide Record while querying for current user in manager field. Use while loop to add all the names of the record whose manager is current user.
If you found this reply useful, please mark it as solution and helpful.
Feel free to reach out for more.
Thanks and Regards,
Ehab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 01:26 AM
Hello @Ramanjaneyuv ,
Please refer below code for a example and update it as per your req:
Client script:
(function() {
// Ensure the script runs when the 'manager' field changes
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Perform a GlideAjax call to fetch users reporting to the selected manager
var ga = new GlideAjax('FetchUsersReportingToManager');
ga.addParam('sys_id', newValue);
ga.getXMLAnswer(function(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
g_form.setValue('users', answer);
});
}
})();
Script include:
var FetchUsersReportingToManager = Class.create();
FetchUsersReportingToManager.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUsers: function() {
var managerId = this.getParameter('sys_id');
var users = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('manager', managerId);
gr.query();
while (gr.next()) {
users.push(gr.name.toString());
}
return users.join('\n');
}
});
Thank you!!
Dnyaneshwaree Satpute
Tera Guru