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 |
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
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.