...
Here's the listing I've been working with: https://yaledevelopmentyale.service-now.com/sys_user_has_role_list.do
I've been working with Alan at Fruition to build up a list of Financial Approver group members who are not also members of any other assignment group. He came up with:
https://yaledevelopmentyale.service-now.com/financial_groupapprovers_singleton_members.do
Code Block |
---|
function findFinancialMembers() { var user_array = []; var user_in_group = new GlideRecord('sys_user_grmember'); user_in_group.addQuery('group', '4da8813ea1a8990494ad46651315d87d'); //Financial Approvers group user_in_group.query(); while (user_in_group.next()) { var group_count = new GlideAggregate('sys_user_grmember'); group_count.addQuery('user', user_in_group.user.sys_id); group_count.addAggregate('COUNT'); group_count.query(); var groups = 0; if (group_count.next()) { groups = group_count.getAggregate('COUNT'); if (groups == 1) { user_array.push(user_in_group.user.user_name); } } } return user_array; } |
...
Code Block |
---|
function findItil() {
var user_array = [];
var role_id = []
var user_has_role = new GlideAggregate('sys_user_has_role');
user_has_role.addEncodedQuery('role=b4c1f5331011100094adb14c071ff154^user.active!=false^user.emailISNOTEMPTY^user.user_nameISNOTEMPTY');
user_has_role.addAggregate('COUNT', 'user');
user_has_role.query();
while (user_has_role.next()) {
user_array.push(user_has_role.user.user_name);
}
return user_array;
}
function findFinancialMembersWithNoOtherRole() {
var user_array = [];
var user_in_group = new GlideRecord('sys_user_grmember');
user_in_group.addQuery('group', '4da8813ea1a8990494ad46651315d87d'); //Financial Approvers group
user_in_group.query();
while (user_in_group.next()) {
var group_count = new GlideAggregate('sys_user_grmember');
group_count.addQuery('user', user_in_group.user.sys_id);
group_count.addAggregate('COUNT');
group_count.query();
var groups = 0;
if (group_count.next()) {
groups = group_count.getAggregate('COUNT');
if (groups == 1) {
user_array.push(user_in_group.user.user_name);
}
}
}
return user_array;
}
function arr_diff(a1, a2)
{
var a=[], diff=[];
for(var i=0;i<a1.length;i++)
a[a1[i]]=true;
for(var i=0;i<a2.length;i++)
if(a[a2[i]]) delete a[a2[i]];
else a[a2[i]]=true;
for(var k in a)
diff.push(k);
return diff;
}
function findItilMinusFinancialMembersWithNoOtherRole () {
var itil_users = findItil();
var finance_no_role_users = findFinancialMembersWithNoOtherRole();
gs.print("The length of itil users is: " + itil_users.length);
gs.print("The length of finance approvers with no other role is: " + finance_no_role_users.length);
var result = arr_diff(itil_users,finance_no_role_users);
gs.print("The subtracted set of elements is: " + result.length);
}
findItilMinusFinancialMembersWithNoOtherRole(); |
*** Script: The length of itil users is: 1183
*** Script: The length of finance approvers with no other role is: 185
*** Script: The subtracted set of elements is: 1000
You would expect that 1183-185 would be 998. So there must be certain elements that somehow are NOT getting counted as ITIL users? So they're not in the original set? So they don't get subtracted? That's the only answer that makes any sense to me. This suggests there is a bug in the ITIL users count. I may need to compare the ITIL users account I get from Allen's method with the one I got from my old way that takes longer.
I compared my long ITIL method against the Alan method and still came up with 1183; so I'm baffled. Anyway, this is a sufficient answer. Going to wrap it, and hand it over.
The method to get the real answer people wanted from me is:
https://yale.service-now.com/itil_without_finance_approver_singletons.do