How to get licensed users ?

Gaurav Kumar15
Giga Guru

Hi All,

We want to check how many licensed users are there in the system. Whenever we see the number of users who are having any role in system from table - "sys_user_has_role", then number comes out to be -1600, but when i am using "getRoledUsers()" function in a script, then it gives me count as 1640. So i am not sure why there is difference between user count from table and script.

Could someone please let me know, how can i calculate licensed users via script.

Regards,

Gaurav Kumar

7 REPLIES 7

ketki_j
Tera Contributor

Hi Gaurav,


Can you please check that in report where the count comes out to be 1640, there might be multiple entries of users with more than 1 role in system.



I applied a script include (client callable)-


function itil_users() {




  var roles = [];


  var user = new GlideRecord("sys_user");


  user.query();


  while(user.next())


  {


  var user_role = new GlideRecord('sys_user_has_role');


  user_role.addQuery('user', user.sys_id);


  user_role.addQuery('role.name','itil'); //edit the role as per your requirement.


  user_role.query();


  while(user_role.next())


  {


  if(user_role.getRowCount() == 1)


  {


  roles.push(user.sys_id.toString());


  }


  }


  }


return roles;


}



And called it via Sys ID IS javascript:itil_users()


ketki_j
Tera Contributor

In my case also, initially there was difference in the no. of licensed users, but on investigation I found that there were several users who have 2 ITIL roles in their profile- one inherited and other granted by admin.


Hi Ketki,



I am using GlideAggregate to get the Unique records based on user.



e.g : In in "User Role" table we have 4 entries of itil for single user, then i am counting that as 1. Still i am getting some difference. I am using below code for calculating the licensed users



var a = getRoledUsers().toString();


var temp = new Array();


temp = a.split(",");




gs.print(temp.length);



So this is give me no. slightly higher than what is getting displayed in User Role table .



Thanks,


Gaurav Kumar


var a = getRoledUsers().toString();


var temp = new Array();


temp = a.split(",");



gs.print(temp.length);


Hi Gaurav,


I applied the same into my instance. I have not made any changes into BR getRoledUsers.



See the snapshots please-


find_real_file.png



Here you can give comma separated roles to get the desired output. For eg-   javascript:getRoledUsers("IN","itil,itil_admin")



There are 25 users in my instance with ITIL roles. Snapshot from sys_user_has_role table is-



find_real_file.png


Chances of increase in number can be only due to increase in number or a   wrong filter.



Please let me know if you face further problem.