Use Jira Assets (Insight) Custom Fields
Summary
SINCE 4.1.12
We have implement some new API classes that provides some methods to extract values from the Insight/Asset objects. These can be used within both JavaScript (Script Field Processor, Script Rule and Script Pre-Proc Task) and Velocity (Templates and Custom Field Defaults).
Velocity Context available for Assets
Context name | Java Doc Page |
---|---|
objectFacade | |
objectSchemaFacade | |
objectTypeAttributeFacade | |
objectTypeFacade |
Example uses with Object Facade classes SINCE 4.1.12
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
Example uses with Object Type Facade class SINCE 4.1.29
Find object type for all object connections made to a specific issue
This example will find the object type for each object that has 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
Example uses with Object Schema class since 4.1.29
Find all object schemas
This example will find the name of all object schemas that are configured within Jira.
#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