JIRA Misc Custom Fields - Calculated Number

Jonathan Chatwin May 23, 2017

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

1 vote
David _old account_
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.
May 23, 2017

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.

0 votes
Jonathan Chatwin May 26, 2017

This works great. Thank you so much for this. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events