Calculated text field using Jira Workflow Toolbox (JWT)

Bharathi
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.
June 4, 2020

I have just started to use JWT plugin and want to create a 'calculated text field' which will have to perform a multiplication like below.

C = A * B, where A & B are custom fields with single select 'text' options.

The selected text options need to be converted to integers and then multiplied. The corresponding result (integer) is to be converted into text and displayed as 'C'. 

Requesting help on the formula to be used in this scenario. Also, even if no option is selected or any 1 is selected, will the calculated text field be able to handle them?

A

Corresponding values

Very High

5

High

4

Medium

3

Low

2

Very Low

1

B

Corresponding values

Very High

5

High

4

Medium

3

Low

2

Very Low

1

C= A * B

References

>= 15

Major

>=10

Serious

>=5

Marginal

<=4

Minor

1 answer

1 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.
June 5, 2020

Hi @Bharathi ,

Given the correct field codes for your fields A and B (here referred to as AAAAA and BBBBB), an expression could look like this:

%{AAAAA} != null AND %{BBBBB} != null ? (setNumber("score",getMatchingValue(%{AAAAA},["Very High","High","Medium","Low","Very Low"],[5,4,3,2,1]) * getMatchingValue(%{BBBBB},["Very High","High","Medium","Low","Very Low"],[5,4,3,2,1])) >= 15 ? "Major" : (getNumber("score") >= 10 ? "Serious" : (getNumber("score") >= 5 ? "Marginal" : "Minor"))) : null

Since this is no trivial expression, please allow me to provide some explanations.

 %{AAAAA} != null AND %{BBBBB} != null

Since this rating only makes sense if both fields are set, it's a good approach to validate both fields being set upfront.

 setNumber("score", // etc.

In order to calculate the overall score only once, we're temporarily storing the result in our variable 'score'. 

getMatchingValue(%{AAAAA},["Very High","High","Medium","Low","Very Low"],[5,4,3,2,1])

In order to 'translate' our single select custom fields, we have to match the options with numeric values. Those values are then multiplied.

Having done all this, it's 'just' comparing the result with the values you've provided within the table for field C and returning the matching string value.

I hope this solution matches your requirement.

Cheers
Thorsten

Bharathi
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.
June 5, 2020

Good morning @Thorsten Letschert _Decadis AG_ ,

Appreciate your help in getting this expression. This looks awesome and the added explanations make it more clear! 

I'll go ahead and try this out in my calculated text field and get back if I have any further questions.

Thanks much!

Bharathi
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.
June 10, 2020

Good morning @Thorsten Letschert _Decadis AG_ ,

The expression works like a charm! I see that, on selecting values for A & B fields in "Create issue" screen, the "C" field is shown with its calculated value in "View issue" screen.

I want to add a description to the "C" field similar to a hover text so that the calculation is made known to end users. I'm using the below script but this wouldn't be shown in "view issue" screen of this particular custom field even though the script works fine for other custom fields. Can you confirm if the addition of description is impossible with a calculated field?

Calculation
<script type="text/javascript">
function showHelp() {
var listenersDiv = document.getElementById("CfieldHelp");
if (listenersDiv.style.display == 'none') {
listenersDiv.style.display = '';
} else {
listenersDiv.style.display='none';
}
}
</script>
<a href="#" onclick="showHelp(); return false;"><img src="/images/icons/ico_help.png"/></a>
<div id="CfieldHelp" style="display:none">
"Major" for >= 15; "Serious" for >= 10; "Marginal" for >= 5 ; "Minor" for <=4
</div>

 

Looking forward to hear from you!

Suggest an answer

Log in or Sign up to answer