Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Insight automation placeholders

David Sumlin June 28, 2022

I have an object type roughly defined as such:

  • Key
  • Name
  • Reference ID (this is a required unique #) 
  • Parent (which is an object attribute pointing back to same object type)

 

I'd like to add another attribute called Parent Reference ID

I was thinking about creating an Insight automation rule which populates this attribute. I'm struggling with the syntax for the Attribute Value placeholder field. I was hoping it would be something like ${Parent.Reference ID} or ${Parent.\"Reference ID\"} or ${Parent.${Reference ID}}...but nothing I do seems to work.

Any ideas on how I can reference an attribute value of the referenced object?

 

** Yes, I realize that having the attribute named Reference ID is a poor design and I also realize that propagating it further into the Parent Reference ID is an even poorer design. :-(

 

1 answer

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 13, 2022

I don't think the automation supports placeholders.

That only works in IQL.

You would need to create a groovy script to update/set the attribute 

Here is an example from the documentation: https://confluence.atlassian.com/insightapps/automation-1085180924.html

Here is a version of the sample script adapted for your use case and rendered a bit more groovy:

import com.atlassian.jira.component.ComponentAccessor
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade
import com.riadalabs.jira.plugins.insight.services.model.factory.ObjectAttributeBeanFactory

def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectFacade)
def objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectTypeAttributeFacade)
def objectAttributeBeanFactory = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectAttributeBeanFactory)

def refOTAB = objectTypeAttributeFacade.loadObjectTypeAttribute(object.objectTypeId, 'Reference Id')
def parentRefOTAB = objectTypeAttributeFacade.loadObjectTypeAttribute(object.objectTypeId, 'Parent Reference Id')
def parentOTAB = objectTypeAttributeFacade.loadObjectTypeAttribute(object.objectTypeId, 'Parent')

def parentObjId = object.objectAttributeBeans.find{it.objectTypeAttributeId == parentOTAB.id}.objectAttributeValueBeans.first().referencedObjectBeanId
def parentObj = objectFacade.loadObjectBean(parentObjId)
def parentRefId = parentObj.objectAttributeBeans.find{it.objectTypeAttributeId == refOTAB.id}.objectAttributeValueBeans.first().value

/* Create the new attribute bean based on the value */
def childOAB = objectAttributeBeanFactory.createObjectAttributeBeanForObject(object, parentRefOTAB, parentRefId)
/* Load the attribute bean */
def objectAttributeBean = objectFacade.loadObjectAttributeBean(object.id, parentRefOTAB.id)
if (objectAttributeBean != null) {
/* If attribute exist reuse the old id for the new attribute */
childOAB.setId(objectAttributeBean.id)
}
/* Store the object attribute into Insight. */
try {
def storedOAB = objectFacade.storeObjectAttributeBean(childOAB);
} catch (Exception e) {
log.warn "Could not update object attribute due to validation exception: $e.message"
}

Remember if you try to attach that script to your automation rule, you will need to add the path of the script in the insight configuration white list

David Sumlin July 26, 2022

Automation definitely accepts some placeholders, but possibly not the full gamut.

I am able to get the groovy script to work, but running into difficulties referencing the path. I'm not sure where my issue is....my whitelisting or my path reference in the automation.

To make matters worse, my path is a Windows path E/Atlassian/Application Data/JIRA/scripts/set-parentreferenceid.groovy

Any ideas?

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 26, 2022

I have only ever interacted with linux installations.

But try E:\\atlassian\\Application Data\\JIRA\\scripts\\set-parentreferenceid.groovy

David Sumlin July 27, 2022

Thanks...I think I had just typed it in wrong. :-(   Anyway, it worked!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events