List of users who have 2 or more Assets assigned

riaz_mansuri
Kilo Guru

Hi,

Does anyone know of a quick way we can report on users who have 2 or more assets assigned to them?

I can get a list of the users but just to know who have 2 or more assets.

Any ideas? What is the best way?

Thanks

1 ACCEPTED SOLUTION

Swapnil Soni1
Giga Guru

Hi,

To get it to work your source table isUsers [sys-user] and under related list conditions select Asset -> Assigned to and change the Greater than or Equal to to 2

Hope this helps

find_real_file.png

 

Please mark correct or helpful.

Thanks

View solution in original post

12 REPLIES 12

Name of Script include should be: getassetsforusers & not one that you have used. Since name is different it is causing issues.

Change the script include name to getassetsforusers

Thanks, I did that but still the same.

find_real_file.png

find_real_file.png

Lost now..... anything else you can think of?

Thanks

Hi,

try below

 var getassetsforusers = Class.create();
getassetsforusers.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    findUserswithMoreThan1Assets: function() {
       
  var arr = [];
		var user = new GlideRecord('sys_user');
		user.query();
		while(user.next()){
			var gr = new GlideRecord('alm_hardware');
			gr.addQuery('assigned_to', user.sys_id);
			gr.query();
			if(gr.getRowCount() >=2){
				arr.push(user.sys_id.toString());
			}
		}
return arr.toString();

    },

    type: 'getassetsforusers'
});

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Above was executed from my end & it fetched results. Can you change 

if (moreassets.getRowCount() > 1) {

to

if (moreassets.getRowCount() > 0) {

once for a check.

Also, ensure you have users with more than 1 or more than 1 assets in system.

Swapnil Soni1
Giga Guru

Hi,

To get it to work your source table isUsers [sys-user] and under related list conditions select Asset -> Assigned to and change the Greater than or Equal to to 2

Hope this helps

find_real_file.png

 

Please mark correct or helpful.

Thanks