Ok makes sense. I ran the query exactly as you provided but it returns an empty array. I think it is due to closing out the first getSubordinates() function since when calling the script include, the recurseUser function doesn’t seem to be part of it. I also got an error saying Parsing Error: unexpected token recurseUsers. Any suggestions?
Ok thank you! Another question - why is userList array being returned after the of statement and not the recurseUser function? Wouldn’t it be better to return the array at the end of the recurseUser function?
Thank you Dave!
What can I do to optimize this one:
Var userlist = [];
var maxlevel = 5;
var level = 1;
Var user = new GlideRecord(‘sys_user’);
If(user.get(gs.getUserID()){
recurseUser(user.sys_id.toString(), level, maxlevel,userList)
}
Function recurseUser(manager,level,maxlevel,userList);
Var emps = new GlideRecord(‘sys_user’);
emp.addActiveQuery();
emp.addQuery(‘manager’,manager);
emp.query();
While(emp.next()){
userList.push(emp.sys_id.toString());
If(level+1 <= maxlevel){
recurseUser(emp.sys_id.toString(),level,maxlevel,userList);
}
}
}
Return userList;
}
This gave me a huge idea :) and I think i can better optimize it by doing like this:
getMyCostCenter(){
var answer;
var user = new GlideRecord(‘sys_user’);
user.get(gs.getUserID());
answer = user.cost_center;
return answer;
}
What do you think of that one?
Yes, I have a script include that is called by the dynamic filter. The script include queries the sys_user table to find the logged in user and then query the cmn_cost_center table and find the cost center associated with the logged in user. Once it is found, it returns it as the answer.
getMyCostCenter: function(){
var answer;
var user = new GlideRecord(‘sys_user’);
user.addQuery(‘sys_id’, gs.getUserID());
user.query();
While(user.next()){
var cc = new GlideRecord(‘cmn_cost_center’);
cc.addQuery(‘sys_id’, user.cost_center’);
cc.query();
If(cc.next()){
answer = cc.sys_id;
}
Return answer;
How can I optimize that query?
Ok I need help with a slow query in it. It’s affecting performance and I’m trying to optimize it for a dynamic filter. Do you know anything about that?
Yes… aim curious to know if you are familiar with ServiceNow?
Got it! Thank you! That actually answered my previous question on the other conversation. I’ll pick your AI brain another day Dave. :) good night!
Just wondering we’re you had gone because you stopped replying to our previous conversation :(
Also - how long are you able to store a conversation? Do you retain the whole thread and able to go back to certain points of the conversation?