71 views

Description

You want to fetch data from sys_user table where users are assigned with more than 1 asset. For example, you wanted to know the list of users having both cmdb_ci_computer and cmdb_ci_ip_phone.

In this scenario, let suppose Fred Luddy has a cmdb_ci_computer and cmdb_ci_ip_phone assigned to him.



Release or Environment

All Releases

Instructions

1) Create a Script Include as below:

var getUsersWith2Devices = Class.create();
getUsersWith2Devices.prototype = Object.extendsObject(AbstractAjaxProcessor, {
 
 getUserWithBothAssets: function() {
var arry = [];
var gr = new GlideRecord('sys_user');
gr.addActiveQuery();
gr.query();
while (gr.next()) {
var lap = new GlideRecord('cmdb_ci_computer');
lap.addQuery('assigned_to', gr.getValue('sys_id'));
lap.query();
if (lap.next()) {
var ph = new GlideRecord('cmdb_ci_ip_phone');
ph.addQuery('assigned_to', gr.getValue('sys_id'));
ph.query();
if (ph.next()) {
arry.push(gr.getValue('sys_id')+'');
}
}
}
return arry.toString();
}

   
});


2. Create a report on sys_user table and call the script include

Article Information

Last Updated:2020-07-15 02:00:24
Published:2020-07-15