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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David,
Thanks for the response. When I use the script you provided, I am greeted with the following error message:
Math expression (Syntax Specification and Examples)
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"))
LEXICAL ERROR: Lexical error at line 1, column 2. Encountered: "f" (102), after : "i"
Could you please advise?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.