It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to dynamically calculate and display WSJF using JMCF or JWT Edited

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

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

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

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"))

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?

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.

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
Community showcase
Published in Jira

The add-in you’ve been waiting for: Jira Cloud for Excel 🙌

Introducing Jira Cloud for Excel Here at the product integrations team at Atlassian, we are thrilled to announce the new Jira Cloud for Excel add-in! This add-in lets you export Jira data directly ...

986 views 11 25
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you