We're using insight and have created an object type with an attribute. This attribute is optional and is only used on a certain set of objects.
In our workflow we use the insight post function "Set a Jira custom field with the attribute value from a selected object". We need a condition where we check whether the attribute is present on the select object. If the condition fails, the target custom field can't be updated.
We've looked into the documentation, but we're not a Java company and struggle with the implementation, so a code example would be most helpful.
The following condition on the "Set a Jira custom field with the attribute value from a selected object" post function will achieve what you're looking for.
You will need to adjust it with the correct customfield ID and Insight attribute name as appropriate.
I've added comments in the code to explain what each line is doing.
import com.atlassian.jira.component.ComponentAccessor
// Get access to the Insight ObjectTypeAttributeFacade class
def objectTypeAttributeFacadeClass = ComponentAccessor.pluginAccessor.classLoader.findClass('com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade')
def objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectTypeAttributeFacadeClass)
// Get the customfield matching the "Source custom field"
def sourceField = ComponentAccessor.customFieldManager.getCustomFieldObject(10100)
// Get the value of the Source custom field from the issue
def sourceFieldValue = issue.getCustomFieldValue(sourceField)?.get(0)
// Find the Insight attribute with the name (matching the "Insight Object Type Attribute name" field)
def objectAttribute = objectTypeAttributeFacade.findObjectTypeAttributeBeans(sourceFieldValue.objectTypeId).find { it.name == 'Attribute Name' }
// This will return true if the attribute is present on the object
sourceFieldValue.objectAttributeBeans.find { it.objectTypeAttributeId == objectAttribute.id } != null
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.