Summary
SINCE 4.1.12
We have implement the Insight ObjectFacade API which now means that you are able to use it’s methods to extract values from Insight/Asset objects. This can be used within both JavaScript (Script Field Processor, Script Rule and Script Pre-Proc Task) and Velocity (Templates and Custom Field Defaults).
For more info about the Object Facade methods see: https://docs.atlassian.com/insight/8.9.2/com/riadalabs/jira/plugins/insight/channel/external/api/facade/ObjectFacade.html
Example uses
Below are some examples of how Insight/Asset objects values can be extracted within Velocity.
Display ObjectId for all connections made to a specific issue
This example will find all of the objects that have been referenced within the issue and will show the Object id’s for each connection.
#if($objectFacade.findObjectTicketConnections($issue.getId())) #set($connections = $objectFacade.findObjectTicketConnections($issue.getId())) #foreach($item in $connections) <p>Object Name and Key: $objectFacade.loadObjectBean($item.getObjectId())</p> #end #end
Output:
Object Name and Key: Object Name (Key)
Find a value of a specific attribute
This example will find the value of a specific object attribute.
#if ($objectFacade.findObjectTicketConnections($issue.getId())) #set($attribute = $objectFacade.loadObjectAttributeBean($objectFacade.findObjectTicketConnections($issue.getId()).get(0).getObjectId(), "Regex").getObjectAttributeValueBeans()) #foreach ($value in $attribute) <p>Attribute value: $value.getValue()</p> #end #end
Output:
Attribute value: Value in attribute
Gathering a value from a specific attribute within a object selected on a Custom Field
This example will gather the objects found within a specific Insight/Asset field and will then compare against made connections on the issue and if matched it will then find the relevant attribute value within that matched object.
#if($objectFacade.findObjectTicketConnections($issue.getId())) #set($connections = $objectFacade.findObjectTicketConnections($issue.getId())) ##Finds all Asset connections made on the issue #set($fieldValue = $customFieldManager.getCustomFieldObject("customfield_11301").getValue($issue)) ##Gathers the Asset objects selected on a specific Field ##Iterates over each fieldvalue #foreach ($object in $fieldValue) #foreach ($item in $connections) ##iterates over each connection made ##Gets Id of the object #set($id = $item.getObjectId()) ##Gets objectbean of the object #set ($objectName = $objectFacade.loadObjectBean($id)) ## Compares if fieldvalue matches the objectbean #if ($objectName == $object) ##Gathers the specific attribute values #set($attribute = $objectFacade.loadObjectAttributeBean($id, "Regex").getObjectAttributeValueBeans()) ##Gathers the specific attribute values <p>Attribute value: $attribute.get(0).getValue()</p> ##Displays attribute value #end #end #end #end
Output:
Attribute: Value in attribute
Find object type of issue objects for all connections made to a specific issue
This example will find object type that have been referenced within the issue
#macro(MacroName) #if($objectFacade.findObjectTicketConnections($issue.getId())) #set($connections = $objectFacade.findObjectTicketConnections($issue.getId())) #foreach($item in $connections) #set($objectBean = $objectFacade.loadObjectBean($item.getObjectId())) <p>Object Name: $objectBean.getName()</p> <p>Object Type: $objectTypeFacade.loadObjectType($objectBean.getObjectTypeId()).getName()</p> #end #end #end
Output:
Object Name: Value Object Type: Connected Device
Find all object schemas
This example will find all object schemas
#macro(MacroName) #if($objectSchemaFacade.findObjectSchemaBeans()) #set($schemas = $objectTypeFacade.findObjectSchemaBeans()) #foreach($schema in $schemas) <p>Object Schema: $schema.getName()</p> #end #end #end
Output:
Object Schema: Car Object Schema: House