I have an object type roughly defined as such:
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. :-(
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
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have only ever interacted with linux installations.
But try E:\\atlassian\\Application Data\\JIRA\\scripts\\set-parentreferenceid.groovy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks...I think I had just typed it in wrong. :-( Anyway, it worked!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.