Get total number of users with itil license

dave_edgar
Mega Guru

Hi

For a special catalog item only available some certain users I want/need to display to total number of active users in a group that already have itil licenses. 

We have users in multiple groups so show in the sys_user_has_role table shows the user multiple times.  So how could I get a total number for the users.  I can't seem to get that work.  I know the count should be 115 but I get 240.

I am getting this via a client script triggering a script include:

var usercount = Class.create();
usercount.prototype = Object.extendsObject(AbstractAjaxProcessor, {
aggregate: function() {
var getcount = new GlideAggregate('sys_user_has_role');
          // getcount.groupBy('user');    // THIS RETURNS 'NULL' 
           getcount.addQuery('role.name','itil');
           getcount.addQuery('user.company.name','STARTSWITH','<company_name>');

           getcount.addQuery
           getcount.query();

while (getcount.next())
{
var users =getcount.user;
var license =getcount.getAggregate("COUNT", users);
gs.log("Users count ==" + license);
}
return license;
},
});

I also tried replacing getcount.addAggregate("COUNT"); AND getcount.getAggregate("COUNT", users);  with getfjscount.addAggregate("COUNT(DISTINCT)","user"); but that NULL's

 

 

6 REPLIES 6

priceless
Tera Expert

Hey Team

Any luck here? am also trying to find the total number of unique users count who has ITIL role returned to a variable.

REgards

Ran

Rashmi Ranjan N
Kilo Contributor

Hi,

Any idea how to restrict ITIL license not be added anymore if counts exceed certain number for itil license.. Want to restrict on Group form and user form too so that its throws errors if unique counts exceed the certain counts for itil..