How to create a custom report that uses a custom resource and custom data classes?
ITMS 8.x
When a custom resource is created, an out-of-box generic report is automatically used for it. The user, however, will often wish to make a more specific custom report that leverages all of the custom resource's data classes. This article describes how to do this.
SELECT cr.Guid, vi.Name
FROM vRM_<custom_resource_name> cr
JOIN vItem vi
ON vi.Guid = cr.Guid
SELECT DISTINCT enim.ItemGuid 'Guid', i.Name 'Custom Resource Name', isn.[Serial Number], ib.Barcode, ic.TempCam, vu.[Given Name] + ' ' + vu.Surname 'Asset Owner'
/*
The SELECT statement returns the following values for each custom resource record:
- The custom resource's GUID as found in the Evt_NS_Item_Management table.
- The custom resource's Name as found in the Item table.
- The custom resource's CMDB Serial Number as found in the Inv_Serial_Number table.
- The custom resource's Barcode Number as found in the Inv_Barcode table.
- The custom resource's custom data class <custom_data_class_name>, as found in the custom data class' table <inv_custom_data_class_name>.
- The custom resource's asset owner (if assigned) association, as found in the ResourceAssociation table and vUser view.
*/
FROM Evt_NS_Item_Management enim
JOIN Item i
ON enim.ItemGuid = i.Guid
LEFT JOIN Inv_Barcode ib
ON enim.ItemGuid = ib._ResourceGuid
LEFT JOIN Inv_Serial_Number isn
ON enim.ItemGuid = isn._ResourceGuid
LEFT JOIN <custom_data_class_name> ic -- Change "<custom_data_class_name> to the name of the custom data class table, such as Inv_Camera_Details.
-- The custom data class table name will always be in the format of Inv_<custom_data_class_name>.
ON enim.ItemGuid = ic._ResourceGuid
LEFT JOIN ResourceAssociation ra
ON enim.ItemGuid = ra.ParentResourceGuid
AND ra.ResourceAssociationTypeGuid = '<resource_association_type_guid>' -- Change <resource_association_type_guid> to the resource association type
-- GUID found by referencing this in the ResourceAssociation table. For
-- example, 'ED35A8D1-BF60-4771-9DDE-092C146C485A' is for a user association.
LEFT JOIN vUser vu
ON ra.ChildResourceGuid = vU.Guid
WHERE ResourceTypeGuid = '<custom_resource_type_guid>' -- Change <custom_resource_type_guid> to the custom resource type GUID found by referencing
-- this in the ResourceType table.
ORDER BY i.Name
Note: In some cases, the user may need to add additional resources and data classes, but may not be sure what tables these are found in. An easy way to determine this is to search the database for a specific value. This would then indicate which possible tables and data classes the values are in for the user to then determine which should be used in the custom report. The following article includes a SQL script that can search the database to help with this process.
How to search a Microsoft SQL database for a data value