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

Jeannette Lamb September 26, 2013

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

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 26, 2013

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.

Jeannette Lamb September 26, 2013

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?

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 26, 2013

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.

Jeannette Lamb September 26, 2013

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

}

Jeannette Lamb September 26, 2013

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

0 votes
Jeannette Lamb September 26, 2013

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?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events