Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

ITIL users used to be an easy query, because it used to be the case that we manually added every ServiceNow user with an assignment group to a separate assignment group called ITIL.

After running like that for a year and a half, it was clear that this was a lot of work and mindless maintenance to keep things going.

Instead, we modified every assignment to grant the ITIL role, and we decommissioned the ITIL assignment group.

This change was non-controversial, and freed up the ServiceNow administrators to do more valuable things with their time.

However, this broke reporting Venkat was using for generating a report for ITIL users.

Venkat needed a new way to pull a report from ServiceNow of ITIL users. It's here:

The business rule is called: Itil Users

The UI page is called: user_has_role_itil

The PROD URL is: https://yale.service-now.com/user_has_role_itil.do

Tech details:

There is a cleaner way to do this, but here's one way to get this list:



var gr2 = new GlideRecord('sys_user_role');

gr2.addQuery('name','itil');

gr2.query();

if (gr2.next() ) {

gs.print('itil group sysid is: ' + gr2.sys_id);

}




//var gr = new GlideAggregate('sys_user'); //GlideAggregate query

var gr = new GlideRecord('sys_user');

gr.addQuery('roles','CONTAINS',gr2.sys_id);

//gr.orderByAggregate('count'); //Count aggregate ordering

//gr.groupBy('email'); //Group aggregate by the 'os' field

gr.query();

var count = 0;

while(gr.next()){

//Print the OS name and count of items with that OS

// gs.print('Distinct operating system: ' + gr.os + ': ' + osCount);

count++;

}

gs.print('count is: ' + count);




var gr3 = new GlideRecord('sys_user_has_role');

gr3.addQuery('role',gr2.sys_id);

gr3.query();

var count2 = 0;

while ( gr3.next() ) {

count2++;

}

gs.print('aoeuaoeeaoeoa count: ' + count2);




var gr4 = new GlideAggregate('sys_user_has_role');

gr4.addQuery('role',gr2.sys_id);

gr4.groupBy('user');

gr4.query();

var count3=0;

while (gr4.next()) {

gs.print('one user record is: ' + gr4.user.email);

count3++;

}

gs.print('4p,p,.puixx.eu count: ' + count3);

 

Tech details round two

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;
}
  • No labels