Summary

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

https://docs.atlassian.com/insight/8.9.2/com/riadalabs/jira/plugins/insight/channel/external/api/facade/ObjectFacade.html

objectSchemaFacade

https://docs.atlassian.com/insight/8.9.2/com/riadalabs/jira/plugins/insight/channel/external/api/facade/ObjectSchemaFacade.html

objectTypeAttributeFacade

https://docs.atlassian.com/insight/8.9.2/com/riadalabs/jira/plugins/insight/channel/external/api/facade/ObjectTypeAttributeFacade.html

objectTypeFacade

https://docs.atlassian.com/insight/8.9.2/com/riadalabs/jira/plugins/insight/channel/external/api/facade/ObjectTypeFacade.html

Example uses with Object Facade classes

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

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

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