How to dynamically calculate and display WSJF using JMCF or JWT

Ogden Rojas September 23, 2019

Hi,

I'm attempting to utilize the Jira Misc Custom Fields plugin to create a calculated WSJF custom field that would dynamically perform mathematical calculations on four single-choice drop-down fields (more context is at https://www.scaledagileframework.com/wsjf/).

The type of formula and the four fields are as follows:

(a + b + c) / d

      Field name                             Possible drop-down values

a.   User-business value               1, 2, 3, 5, 8, 13, 20

b.   Time criticality                        1, 2, 3, 5, 8, 13, 20

c.   RR | OE Value                          1, 2, 3, 5, 8, 13, 20

d.   Job Size                                  1, 2, 3, 5, 8, 13, 20

 

Each of these fields look like they're being treated as text.  Therefore, I'll need to convert each of them to integers before performing the calculation.

Does anyone know what options and formula would work so that any time one of those four fields above is changed, the WSJF field automatically recalculates and displays the new result as a number?  Thanks.

2 answers

2 accepted

1 vote
Answer accepted
Thorsten Letschert _Decadis AG_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
September 25, 2019

Hi @Ogden Rojas ,

your expression should look like this:

(%{aaaaa} != null AND %{bbbbb} != null AND %{ccccc} != null AND %{ddddd} != null) ? (toNumber(%{aaaaa}) + toNumber(%{bbbbb}) + toNumber(%{ccccc})) / toNumber(%{ddddd}) : null

Please replace all the field codes used with the ones of your fields, e.g. if your User-business value field has the id 11200, replace aaaaa with this value. The field code injectors present should help here.

In the first part of the expression - before the quotation mark - we're ensuring every field has a value. In the second part the actual calculation is done.

Please let me know if that solves your problem.

Cheers
Thorsten

Ogden Rojas October 28, 2019

Hi Thorsten,

This seems to work fine except for one issue I'm encountering.  If the calculated field returns a null value, then those null values are at the very top of the list when I use the ORDER BY DESC clause in JQL filters.

Is there a way to make it so that JIRA issues with this field as a null value are at the bottom of the list instead of at the top where the highest numbers should be? ...or maybe have the field default to a value of zero instead?

 

Thanks,

Ogden

0 votes
Answer accepted
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 23, 2019

Hi,

The following assumes you're using JMCF 2.

You first need to handle null (empty) values. The safest is to return null when any of the fields is empty but you could adapt the script if you want another behavior. 

Then, you need to convert the select-field value into a number, using Integer.parseInt(String).

Finally, you just return the result of the calculation, making sure you do floating-point calculation if you don't want integer rounding of the result.

So, you could try something like this:

if (issue.get("User-business value") == null || issue.get("Time criticality") == null || issue.get("RR | OE Value") == null || issue.get("Job Size") == null)
return null
return (Double.parseDouble(issue.getAsString("User-business value")) + Integer.parseInt(issue.getAsString("Time criticality")) + Integer.parseInt(issue.getAsString("RR | OE Value"))) / Integer.parseInt(issue.getAsString("Job Size"))
Ogden Rojas September 24, 2019

Hi David,

Thanks for the response.  When I use the script you provided, I am greeted with the following error message:

XPECTED EXPRESSION TYPE:

Math expression (Syntax Specification and Examples)

 

EXPRESSION:

if (issue.get("User-business value") == null || issue.get("Time criticality") == null || issue.get("RR | OE Value") == null || issue.get("Job Size") == null) return null return (Double.parseDouble(issue.getAsString("User-business value")) + Integer.parseInt(issue.getAsString("Time criticality")) + Integer.parseInt(issue.getAsString("RR | OE Value"))) / Integer.parseInt(issue.getAsString("Job Size"))

 

PARSE RESULT:

LEXICAL ERROR: Lexical error at line 1, column 2. Encountered: "f" (102), after : "i"

 

Could you please advise?

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 24, 2019

Hi,

that's because you did not create a JMCF calculated field, but a field type provided by Decadis (I guess the SumUp app).

You need to create a Calculated Number Field.

Ogden Rojas September 24, 2019

Thanks David.  It seems to work after testing now.  However, I just realized that our organization doesn't actually have a license for JMCF.  Is there a way to get the same result without using JMCF?

Suggest an answer

Log in or Sign up to answer