I created a scripted field called Severity which returns a value from 1-5 based on Impact and Urgency. I now want to update the JIRA default Priority field with the Severity value (and just hide the Severity field).
I am looking at the Behaviours Plugin. I've created a Behaviour and using fields Priority and Severity, with Severity as readonly. I've mapped the Behaviour to all issue types and all projects. Below is the serverside script attached to the Priority field.
FormField severity = getFieldById("customfield_11302") FormField priority = getFieldById("priority") if (severity.getValue() == 1) { priority.setFormValue("1") } else if (severity.getValue() == 2) { priority.setFormValue("2") } else if (severity.getValue() == 3) { priority.setFormValue("3") } else if (severity.getValue() == 4) { priority.setFormValue("4") } else if (severity.getValue() == 5) { priority.setFormValue("5") }
This is not working. Any ideas on how to get this working? Or a better method?
Other small changes I've tried is severity.getFormValue() and even enclosing the severity values in "". None have any change.
One possible soution (severity is select custom field):
FormField fseverity = getFieldById(fieldChanged)
FormField fpriority = getFieldById("priority")
FormField fpriority0 = getFieldById("priority-field")
String vpriority = (String) fpriority.getFormValue()
String vseverity = (String) fseverity.getFormValue()
// option id for Blocker (from table CUSTOMFIELDOPTION, field ID, you can filter by field CUSTOMFIELD): 12179
// you can also get value by uncoment following line:
// fpriority.setHelpText("Severity:" + vseverity)
if (vseverity == "12175") {
fpriority0.setFormValue("Blocker")
fpriority.setFormValue(1)
}
else if (vseverity == "12176"){
fpriority0.setFormValue("Critical")
fpriority.setFormValue(2)
}
else if (vseverity == "12177"){
fpriority0.setFormValue("Major")
fpriority.setFormValue(3)
}
else if (vseverity == "12178"){
fpriority0.setFormValue("Minor")
fpriority.setFormValue(4)
}
else {
fpriority0.setFormValue("Trivial")
fpriority.setFormValue(5)
}
Thanks Vidic, but I'm not sure that will help my problem. My severity if a scripted field custom field, not select. This is because severity is based on what Impact & Urgency values exist and will change if either one changes. I'm not sure a select cf would accomplish the same?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Workaround: You can also read Impact and Urgeny at the beginning of code and calculate the severity on the same way as it is calculated in scripted field (with combination of "if ... else" or "Switch ... case").
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So I tried combining the if...else I used in the scripted field and moved it into the behaviour for the Priority field:
FormField fimpact = getFieldById("customfield_11300") FormField furgency = getFieldById("customfield_11301") FormField fpriority = getFieldById("priority") FormField fpriority0 = getFieldById("priority-field") String Imp = (String) fimpact.getFormValue() String Urg = (String) furgency.getFormValue() if (Imp == "High" && Urg == "High") { fpriority0.setFormValue("Critical") fpriority.setFormValue(1) } else if (Imp == "High" && Urg == "Medium") { fpriority0.setFormValue("Signficiant") fpriority.setFormValue(2) } else if (Imp == "High" && Urg == "Low") { fpriority0.setFormValue("Major") fpriority.setFormValue(3) } else if (Imp == "Medium" && Urg == "High") { fpriority0.setFormValue("Signficiant") fpriority.setFormValue(2) } else if (Imp == "Medium" && Urg == "Medium") { fpriority0.setFormValue("Major") fpriority.setFormValue(3) } else if (Imp == "Medium" && Urg == "Low") { fpriority0.setFormValue("Important") fpriority.setFormValue(4) } else if (Imp == "Low" && Urg == "High") { fpriority0.setFormValue("Major") fpriority.setFormValue(3) } else if (Imp == "Low" && Urg == "Medium") { fpriority0.setFormValue("Important") fpriority.setFormValue(4) } else if (Imp == "Low" && Urg == "Low") { fpriority0.setFormValue("Trivial") fpriority.setFormValue(5) }
But still nothing. I've definetly mapped the behaviour and am unsure why it seems to do nothing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My upper commment is for custom fields (impact and urgency)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use custom field option ids (example: "12176") instead of text (example: "Critical") - from table CUSTOMFIELDOPTION, field ID. You can filter these values by field CUSTOMFIELD.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
if problem still persist you can also try to change (for impact and urgecy):
from FormField fimpact = getFieldById("customfield_11300"
)
to
FormField fimpact = getFieldByName ("Your field name, maybe Impact")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Another way to get values of custom fields impact and urgency:
Uncomment all except these
FormField fimpact = getFieldByName (
"Impact fiel name"
)
FormField furgency = getFieldByName (
"Urgency field name"
)
FormField fpriority = getFieldById(
"priority"
)
FormField fpriority0 = getFieldById(
"priority-field"
)
String Imp = (String) fimpact.getFormValue()
String Urg = (String) furgency.getFormValue()
// show current value of impact option id
fimpact.setHelpText("Impact:" + Imp )
// show current value of urgency option id
furgency.setHelpText("Urgency:" + Urg)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for all the help Vidic.
This is what now works:
FormField fimpact = getFieldByName("Impact") FormField furgency = getFieldByName("Urgency") FormField fpriority = getFieldById("priority") FormField fpriority0 = getFieldById("priority-field") String Imp = (String) fimpact.getFormValue() String Urg = (String) furgency.getFormValue() if (Imp == "10800" && Urg == "10803") { fpriority.setFormValue("1") } else if (Imp == "10800" && Urg == "10804") { fpriority.setFormValue("2") } else if (Imp == "10800" && Urg == "10805") { fpriority.setFormValue("3") } else if (Imp == "10801" && Urg == "10803") { fpriority.setFormValue("2") } else if (Imp == "10801" && Urg == "10804") { fpriority.setFormValue("3") } else if (Imp == "10801" && Urg == "10805") { fpriority.setFormValue("4") } else if (Imp == "10802" && Urg == "10803") { fpriority.setFormValue("3") } else if (Imp == "10802" && Urg == "10804") { fpriority.setFormValue("4") } else if (Imp == "10802" && Urg == "10805") { fpriority.setFormValue("5") }
However, one slight glitchy thing is when I change Impact & Urgency the Priority won't update at first. I have to back into 'Edit' and hit 'Update' again for it to trigger the Priority change.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just one more comment/opinion:
You have to add code (just in case of priority field): fpriority0.setFormValue("Major") next to fpriority.setFormValue(3
)
fpriority.setFormValue(3
) change value in issue
fpriority0.setFormValue("Major") change value in current form (custom screen, Edit screen,...)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should add some debug, eg to log the value and type of the severity FormField.
I expect it will be a string, so severity.getFormValue() == 1 won;t work, you should use: severity.getFormValue() == "1"
But you should still add some logging... eg log.warn (...)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've added in some debug and checked the log. This is what I'm getting:
[onresolve.jira.groovy.GroovyCustomField] javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method getValue() on null object
Is it just not possible to get the value of the Scripted Field cf?
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.