Display all the assets assigned to User

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2022 02:26 AM
Hi Experts,
We have a requirement, it is to Display all the assets assigned to Affected user in a catalog item. Affected user is a reference variable pointing to (sys_user table).
If user has one asset it should display as below image (1)
If the affected user has multiple devices it should display as below image (2)
Note: Assets should be displayed from cmdb_ci_computer table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2024 10:04 PM
@James Rostron Please use the following modified script include code
var getAssetProperties= Class.create();
getAssetProperties.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAssetDetails: function() {
var arr = [];
var grAsset = new GlideRecord('cmdb_ci_computer');
grAsset.addQuery('assigned_to', this.getParameter('user'));
grAsset.query();
while(grAsset.next()) {
arr.push({'<pass asset tag variable name here>' : grAsset.getValue('asset_tag'), '<pass manufacturer variable name here>' : grAsset.getValue('manufacturer'), '<pass model id variable name here>' : grAsset.getValue('model_id'), '<pass serial number variable name here>' : grAsset.getValue('serial_number')}) //Store the details in JSON format
}
return JSON.stringify(arr);
},
type: 'getUserPropertiesAjax'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 05:30 AM - edited 12-16-2024 05:31 AM
For anyone else drawn to this article I managed to fix the code so that multiple assets are returned.
See updated script include below:
NB: Update with your variable names
var getAssetProperties = Class.create();
getAssetProperties.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAssetDetails: function() {
var arr = [];
var grAsset = new GlideRecord('cmdb_ci_computer');
grAsset.addQuery('assigned_to', this.getParameter('user'));
grAsset.query();
while (grAsset.next()) {
arr.push({
'name': grAsset.getValue('name'),
'manufacturer': grAsset.getDisplayValue('manufacturer'),
'model': grAsset.getDisplayValue('model_id'),
'serial_number': grAsset.getValue('serial_number')
}) //Store the details in JSON format
}
return JSON.stringify(arr);
},
type: 'getAssetProperties'
});