Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Set a condition on an insight post function, by looking at an attribute

Frederik De Roover
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 14, 2021

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.

1 answer

3 votes
Gareth Cantrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 14, 2021

Hi @Frederik De Roover 

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

Suggest an answer

Log in or Sign up to answer