- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2023 09:06 AM
I have a PA Script that is not behaving as expected. I call the same function multiple times. If I comment out the code and just call it once, it works perfectly. It is when I call it multiple times that the trouble begins. When I call it the second time and subsequent times after that, the numbers it returns are exponentially higher than they should be. Does anyone know why this would be? Any of the scenarios if I call the function individually work properly, just not in combination with each other. Your help is greatly appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2023 10:21 AM
Seems the issue was the way I was adding. I was concatenating rather than adding. This worked!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2023 10:06 AM
Hi @Renita ,
can you please try the below code -
var directreports = function(x, y) {
var ga = new GlideAggregate('sys_user');
ga.addAggregate('COUNT', y.toString());
ga.addQuery('active', '=', 'true');
ga.addQuery('u_outsourced', '=', 'false');
ga.addNotNullQuery('employee_number');
ga.addNotNullQuery('email');
ga.addNotNullQuery('first_name');
ga.addQuery(y.toString(), '=', x);
ga.query();
ga.clear();
if (ga.next()) {
return ga.getAggregate('COUNT', y.toString());
} else return 0;
}
var CIODirectsReports = function() {
var mgr = current.sys_id;
var levels = [
'manager',
'manager.manager',
'manager.manager.manager',
'manager.manager.manager.manager',
'manager.manager.manager.manager.manager',
'manager.manager.manager.manager.manager.manager',
'manager.manager.manager.manager.manager.manager.manager',
'manager.manager.manager.manager.manager.manager.manager.manager',
'manager.manager.manager.manager.manager.manager.manager.manager.manager',
'manager.manager.manager.manager.manager.manager.manager.manager.manager.manager'
];
var totalcount = 0;
for (var i = 0; i < levels.length; i++) {
var peoplecount = directreports(mgr, levels[i]);
totalcount += peoplecount;
}
return totalcount;
}
CIODirectsReports();
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Regards,
Tushar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2023 10:21 AM
Seems the issue was the way I was adding. I was concatenating rather than adding. This worked!