JIRA Misc Custom Fields - Calculated Number

Hello, I need some help as I am a groovy/beanshell newb!

I am trying to take the highest value of 3 number fields (risk1, risk2, risk3) and multiply that by a fourth number field (probability) to set a 5th value (residual risk rating). Can anyone steer me in the right direction, maybe give some example code? I've looked around on this tag and have not seen anything similiar! Any help would be greatly appreciated. 

2 answers

You can create a Calculated Number Field, and in the description of that field (Field->Edit), type something like:

<!-- @@Formula:
if (issue.get("<field4>")==null) 
  return null;
Double m = 0;
if (issue.get("<field1>") != null && issue.get("<field1>") > m)
  m = issue.get("<field1>") ;
if (issue.get("<field2>") != null && issue.get("<field2>") > m)
  m = issue.get("<field2>") ;
if (issue.get("<field3>") != null && issue.get("<field3>") > m)
  m = issue.get("<field3>") ;
return m * issue.get("<field4>"); 

where <field1> ... <field4> are the names of the four Number fields. Note that:

1) these fields must be Number fields - not text fields containing a number (otherwise some conversion is required)

2) the sample code above returns null if any of the fields is null - you might want a different strategy, such as ignoring empty fields 1 to 3.

This works great. Thank you so much for this. 

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

86 views 0 5
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