Hi,
I wonder if I could get some help with this problem.
(I'm a C++ developer by trade so apologies in advance if my script code isn't the best.)
I've used the script runner plugin to create a custom scripted field to calculate a 'Fix urgency' field from three other fields as follows:
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.MutableIssue
import org.apache.log4j.Category
ComponentManager compManager = ComponentManager.getInstance()
CustomFieldManager cfm = compManager.getCustomfieldManager()
CustomField cfFreq = cfm.getCustomfieldObjects(issue).find{ it.name == "Frequency" }
CustomField cfPrev = cfm.getCustomfieldObjects(issue).find{ it.name == "Prevalance" }
CustomField cfSev = cfm.getCustomfieldObjects(issue).find{ it.name == "Severity" }
frqVal = issue.getCustomeFieldValue(cfFreq).toString()
prevVal = issue.getCustomeFieldValue(cfPrev).toString()
sevVal = issue.getCustomeFieldValue(cfSev).toString()
def urgencyResult = GetUrgency(frqVal, prevVal, sevVal)
def GetUrgency(fre, prev, sev)
{
def urgency = [ 3:"Urgent(Hotfix)", 2:"Medium(Service Pack)", 1:"Low(Next Release)" ]
def frequency = [ Rare:1, Occasional:2, Often:3 ]
def prevalence = [ Few:1, Some:2, Most:3 ]
def severity = [ Cosmetic:1, Inconvenience:2, LossOfFunction:3, Catastrophic:4 ]
def calcVal = frequency[fre] * prevalance[prev] * severity[sev]
def lookup = 1
if (calcVal < 6) { lookup = 1 }
else if (calcVal > 22) { lookup = 3 }
else { lookup = 2 }
return urgency[ lookup ]
}
return urgencyResult == null ? "Undefined or Legacy issue" : urgencyResult
This works great in a normal screen (ie after a transition) but the original idea is that in a transition screen the 3 source fields (Frequency, Prevalance and Severity) are set which causes the 'Urgency' field to be calculated. This field then provides information (still in the transition screen) to enable the user to select a target release for the fix.
From what I could discover using google the behaviours plugin should do the job as I want it, but I don't know how to modify the above script so that it references fields on the same transition screen. Is this even possible?
It would also be great if the calculated 'Urgency' was persisted so it could be viewed in the issue afterwards.
I'd be really, really grateful for any assistance with this.
Thanks in advance.
Mark