Jira Insight Groovy Condition

Jason Whitaker February 7, 2021

I'm trying to create a groovy script to perform a condition based on the attribute value of an insight custom field. The problem is the attribute value I require is a referenced object which is again another referenced object.

For example I have a object called computer with an attribute called "Computer Model" that is a referenced object. The "Computer Model" object has an attribute called "Manufacturer" that is also a referenced object. The Manufacturer object just has one attribute called name which I require the value of.

I have modified some code I have used in the past that is currently outputting the object id of the Computer Model.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade")
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass)

CustomField Warranty = customFieldManager.getCustomFieldObject('customfield_10800')
ArrayList myValue = issue.getCustomFieldValue(Warranty) as ArrayList
ArrayList myAttributes = []

myValue.each {
if (objectFacade.loadObjectAttributeBean(it.getId(), 237))
{def myAttrValue = objectFacade.loadObjectAttributeBean(it.getId(), 237).getObjectAttributeValueBeans()[0].getValue()
myAttributes.add(myAttrValue)}
}

return myAttributes[0]

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events