Hello all,
we are trying to calculate a priority for an Insight object, based on different categories. The whole thing looks like the following example:
Object A:
Attribute Priority Categories: Multiple selection from category 1-5
Attribute Priority: Numeric calculated value based on priority categories
Category 1: Value of 20
Category 2: value of 50
Category 3: value of 10
...
So if an object A has category 1 and 2, the value 70 should be calculated as priority.
Does anyone have ideas what possibilities can be offered for this?
Thanks in advance for your help!
The actual logic for this is fairly simple ... what's hard is to get the Category values and then update another attribute.
With the utility class I created (see this article) I can achieve your requirement with this script in the insight groovy console:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.util.JiraHome
def jiraHome = ComponentAccessor.getComponent(JiraHome).home
InsightUtils = new GroovyClassLoader(getClass().classLoader).parseClass(new File("$jiraHome/scripts/com/qad/qsm/jira/insight/InsightUtils.groovy"))
def cat = InsightUtils.getAttributeValueFromDotNotation(object, 'Priority Category') as List
def map = ['Category 1':20, 'Category 2':50, 'Category 3':10]
def priority = cat.sum { map[it] }
InsightUtils.setObjectAttribute(object, 'Priority', priority)
To do the same from scratch, it would look more like this:
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.ObjectTypeFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectFacade)
def objectTypeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectTypeFacade)
def objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectTypeAttributeFacade)
def objectType = objectTypeFacade.loadObjectType(object.objectTypeId)
def priorityCategoryAttr = objectTypeAttributeFacade.findObjectTypeAttributeBeans(objectType.id).find {it.name == 'Priority Category'}
def priorityAttr = objectTypeAttributeFacade.findObjectTypeAttributeBeans(objectType.id).find {it.name == 'Priority'}
def categories = object.objectAttributeBeans.find{it.objectTypeAttributeId == priorityCategoryAttr.id}?.objectAttributeValueBeans*.value
def categoryPrioritValuesMap = ['Category 1':20, 'Category 2':50, 'Category 3':10]
def priority = categories.sum { categoryPrioritValuesMap[it] }
log.info("Priority will be set to $priority")
def newPriorityBean = object.createObjectAttributeBean(priorityAttr)
def newPriorityValue = newPriorityBean.createObjectAttributeValueBean()
newPriorityValue.setValue(priorityAttr, priority)
newPriorityBean.setObjectAttributeValueBeans([newPriorityValue])
objectFacade.storeObjectAttributeBean(newPriorityBean)
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.