- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 11:16 AM
Suppose:
User1
User2 : Manager is User1
User3 : Manager is User2
User4 : Manager is User3
Fetch the records from user table using recursion
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 02:56 PM
Try this code:
function getManager(userID){
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',userID);
gr.query();
while(gr.next()){
if(gr.manager){
var output=getManager(gr.manager);
output=gr.manager.getDisplayValue()+' -> '+output;
return output;
}
else return null;
}
}
gs.print(getManager('02826bf03710200044e0bfc8bcbe5d3f')); //this is the sys_id of User 1
hope this help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 02:56 PM
Try this code:
function getManager(userID){
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',userID);
gr.query();
while(gr.next()){
if(gr.manager){
var output=getManager(gr.manager);
output=gr.manager.getDisplayValue()+' -> '+output;
return output;
}
else return null;
}
}
gs.print(getManager('02826bf03710200044e0bfc8bcbe5d3f')); //this is the sys_id of User 1
hope this help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2020 05:47 AM
I have tried this script but it is only working in Scripts- Background option. Applying in relationship on user table it's not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2020 09:44 PM
Hi Denise,
Below link may help you achieving your scenario,
Note: Replace the tablename with sys_user and request with userID
Regards,
Subhojit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2023 12:43 AM
Hi All,
I have solved this requirement using below code.
function getManager(id){
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', id);
gr.query();
var result;
if(gr.next()){
if(gr.manager){ //Shanna - Aileen - Amos - Angelique - Angelo
result = getManager(gr.manager);
if(result==null){
result = gr.manager.getDisplayValue();
}
return result;
}
else{
return null;
}
}
}
function getUsername(id){
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', id);
gr.query();
if(gr.next()){
return gr.first_name + " " + gr.last_name;
}
}
sysid='62826bf03710200044e0bfc8bcbe5df1';
gs.print(getUsername(sysid) + " : " + getManager(sysid));