I have a custom field that is a Calculated Number Field. I am trying to compare the selected value of a Select List (single choice) field with a string. However, my comparison always returns false even when the selected value matches the string being compared with.
In the formula below, the return value is always 0 (unless the field is null, then it's -1).
The field value is "3-Moderate" but when I compare the field value using issue.get with "3-Moderate" it returns false. I have also tried adding toString() after issue.get() and that does not work either.
Calculated Number Field Formula
<!-- @@Formula: var severity = issue.get("customfield_11600"); log.error("value of severity is " + severity); var moderate = "3-Moderate"; log.error("value of moderate is " + moderate); (severity != null ? ((severity == moderate) ? 1 : 0) : -1) -->
JIRA Debug Log
2016-10-28 13:21:13,056 http-bio-8080-exec-43 ERROR username 801x81376x2 1p9ubvx ip.address.hidden /secure/AjaxIssueEditAction!default.jspa [innovalog.jmcf.fields.CalculatedNumberField] value of severity is 3-Moderate 2016-10-28 13:21:13,056 http-bio-8080-exec-43 ERROR username 801x81376x2 1p9ubvx ip.address.hidden /secure/AjaxIssueEditAction!default.jspa [innovalog.jmcf.fields.CalculatedNumberField] value of moderate is 3-Moderate
JIRA version v6.3.15 and JMCF version 1.7.1.
You should not be using JMCF 1.7.x on JIRA 6.3. JMCF 1.7.x is for JIRA 7 and above.
As for your formula, you should compare strings using the equals() method:
<!-- @@Formula: var severity = issue.get("customfield_11600"); log.error("value of severity is " + severity); var moderate = "3-Moderate"; log.error("value of moderate is " + moderate); (severity != null ? ((severity.equals(moderate)) ? 1 : 0) : -1) -->
Thank you, @David [Innovalog].
The severity.equals(moderate) resolved my issue. I've also put in a request to have our local JIRA instance upgraded to the latest version.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@David [Innovalog]
This is great - Thanks heaps
I have an extension question if its okay.
I ideally want to compare and assign a value based on a combination of two values Consequence and Likelihood. SO I have tried this. Assigning a var to each field.
Creating a var for the values they can equal. But I can't get the second condition to fire. I.e I can get it to work if likelihood = Possible and Consequence = Minimal but if the value = Moderate it doesn't work. If I switch them it works for the frist but not the other. Any idea how I can get a number of conditions to check like this?
It seems I can only compare one condition at a time?
<!-- @@Formula:
var Likelihood = issue.get("customfield_10102");
var Consequence = issue.get("customfield_10101");
var Minimal = "Minimal";
var Moderate = "Moderate";
var Possible = "Possible";
((Consequence.equals(Minimal))||(Likelihood.equals(Possible))? "MinPos": null))
((Consequence.equals(Moderate))||(Likelihood.equals(Possible))? "ModPos";0))
-->
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry should mention I had picked up the semi colon and its not that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just an update I managed to do this via a three step process
Consequence
<!-- @@Formula: var Consequence = issue.get("customfield_10101"); var Minor = "Minor"; var Minimal = "Minimal"; .. if (Consequence.equals(Minor)) return 1; if (Consequence.equals(Minimal)) return 2; .. return 0;-->
Likelihood
<!-- @@Formula: var Likelihood = issue.get("customfield_10102"); var Rare = "Rare"; var Unlikely = "Unlikely"; var Possible = "Possible"; .. if (Likelihood.equals(Rare)) return 1; if (Likelihood.equals(Unlikely)) return 2; if (Likelihood.equals(Possible)) return 3; .. return 0;-->
Multiply one by the other
<!-- @@Formula: (issue.get("customfield_10200") != null ? issue.get("customfield_10200") : 0) * (issue.get("customfield_10109") != null ? issue.get("customfield_10109") : 0) -->
Note the icon on the extreme value
<!-- @@Formula: var Level_Result = issue.get("customfield_10201"); if (Level_Result > 14) return "<img src='/images/icons/priority_blocker.gif'> "+"Extreme"; else if (Level_Result >= 10) return "Medium"; else return "Low"; -->
Hope that helps someone.
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.