Scriptrunner - How to get attribute values from insight custom field with multi objects

Florian Schüller February 13, 2019

Hi Community!

I try to get the attribute values from a multi user/multi object insight custom field.

I tried a lot, but i only get the attribute value from the first object. (the object which is alphabetic first)

I would like to get the attribute values comma seperated as result.

If someone could help me i would be very grateful :)

best regards,

Florian

 

This is the part, where i get the attribute value from the insight custom field (only the attribute from the first object):

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

CustomField Benutzername = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(11003) // ID von Customfield "Anfrage für"
def myValue = Benutzername.getValue(issue)
def myObjectBean = myValue[0]
def myAttrValue = objectFacade.loadObjectAttributeBean(myObjectBean.getId(), 1293).getObjectAttributeValueBeans()[0]; // ID von Attribute "Benutzername AD" vom Object Person
def myString = myAttrValue.getValue()

 

1 answer

1 accepted

2 votes
Answer accepted
Alejandro Suárez - TecnoFor
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
February 13, 2019

Hi @Florian Schüller,

You can use this:

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 Benutzername = customFieldManager.getCustomFieldObject(11003L) // ID von Customfield "Anfrage für"
ArrayList myValue = issue.getCustomFieldValue(Benutzername) as ArrayList
ArrayList myAttributes = []

myValue.each {
def myAttrValue = objectFacade.loadObjectAttributeBean(it.getId(), 1293).getObjectAttributeValueBeans()[0].getValue() // ID von Attribute "Benutzername AD" vom Object Person
myAttributes.add(myAttrValue)
}

log.warn myAttributes

Edit: I readed again your post. Here you go, the variable "myAttributes" have the attributes list comma separated.

Regards!

Florian Schüller February 13, 2019

Thank you @Alejandro Suárez - TecnoFor

 

This works great! 

Now i can use the variable for a DB Insert :)

 

Have a nice day.

 

best regards,

Florian

Suggest an answer

Log in or Sign up to answer