Summary
This article describes how to retrieve data from the sys_user table when a user is assigned to more than one asset.
For example, to obtain a list of users who have both cmdb ci computer and cmdb ci ip phone. Assume Fred Luddy is assigned a cmdb ci computer and a cmdb ci ip phone in this scenario.
Instructions
- 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();
}
}); - Create a report on sys_user table and call the script include