can I script a mathematically calculation if using number values in a radio button or select list?

can I run a script to multiply 3 numbers if the 3 number's fields are either radio buttons or select list? I need to restrict what values can be entered for risk_severity, risk_probability and risk_detectability.

I tried making one of the fields a radio button then ran my script (in scripted field) and am getting the following message.

javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.customfields.option.LazyLoadedOption.multiply() is applicable for argument types: (java.lang.Double) values: [3.0]

def Risk_Severity = getCustomFieldValue("Risk Severity - radio") def Risk_Probability = getCustomFieldValue("Risk Probability") def Risk_Detectability = getCustomFieldValue("Risk Detectability") if (Risk_Severity) { return (Risk_Severity * Risk_Probability) * Risk_Detectability } else { return null }

2 answers

This widget could not be displayed.

If I can't use radio button or select list to restrict what the user can enter, I would like to add a condition to a workflow transition. I tried adding a condition type "simple scripted validator" and tried the following sample condition

cfValues['Risk Severity'].value == '1'

It isn't working because it displays my chosen error message even if I have entered a 1 into the Risk Severity field.

I need the condition to display a message "Risk Severity can only be 1, 2, or 3. (1=Low, 2=Med, 3=High)" if the Risk Severity is not 1,2,or3.

Can someone help me with the syntax?

Thank you,

Jeannette

p.s. - also, is there a way to have the condition only run if Issue Type = Bug without having to create a separate workflow?

This widget could not be displayed.

The value is the name of the option - is it definitely "1"?

Why don't you log it using assert in condition tester: https://jamieechlin.atlassian.net/wiki/display/GRV/Built-In+Scripts#Built-InScripts-PowerAssertions

Then you can see exactly why it's not equal to that.

I tried this in my condition and am getting the error below.

assert cfValues['Risk Severity'].value == '1' || cfValues['Risk Severity'].value == '2' || cfValues['Risk Severity'].value == '3'

The JIRA server was contacted but has returned an error response. We are unsure of the result of this operation.

Close this dialog and press refresh in your browser

However, I'm not going to be able to use this unless I can also ONLY run the validator if the issue type = Bug. So I guess I'm back to my original question which is whether or not I can multiply values in a scripted field if the variable fields are radio button or select list?

What version are you using - must be an old one?

> multiply values in a scripted field if the variable fields are radio button or select list?

Yes, you just need to cast them to Integers.

(cfValues['Some Field'].value as Integer) * 2 > 10

but check for nulls.... test with issues without the field set at all as well as with.

Here is my draft script. Do I add .value as Integer to each field in the return line?

def Risk_Severity = getCustomFieldValue("Risk Severity")

def Risk_Probability = getCustomFieldValue("Risk Probability")

def Risk_Detectability = getCustomFieldValue("Risk Detectability")

if (Risk_Severity) {

return (Risk_Severity * Risk_Probability) * Risk_Detectability

}

else {

return null

}

apologies for the basic questions. I do most of our JIRA administration but I am not a developer.

we are using JIRA 5.0.1 (planning to upgrade to 6.0.8 next week)

script runner plugin is version 2.0.4

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

536 views 3 19
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you