JMCF - How to Compare a Selected List Value with a String

Jacob Clouse October 28, 2016

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.

1 answer

1 accepted

0 votes
Answer accepted
David _old account_
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.
October 28, 2016

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)
-->
Jacob Clouse October 28, 2016

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.

James Webber November 26, 2016

@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))
-->
James Webber November 27, 2016

Sorry should mention I had picked up the semi colon and its not that.

James Webber November 27, 2016

Just an update I managed to do this via a three step process

1: Number field for each value

Consequence

&lt;!-- @@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;--&gt;

Likelihood

&lt;!-- @@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;--&gt;

2: Calculated value Result

Multiply one by the other

&lt;!-- @@Formula: 
(issue.get("customfield_10200") != null ? issue.get("customfield_10200") : 0) * 
(issue.get("customfield_10109") != null ? issue.get("customfield_10109") : 0) --&gt;

3: Finally a new status based on the result value

Note the icon on the extreme value

&lt;!-- @@Formula:
var Level_Result = issue.get("customfield_10201");
if (Level_Result &gt; 14)  
return "&lt;img src='/images/icons/priority_blocker.gif'&gt; "+"Extreme"; 
 
else if (Level_Result &gt;= 10)  return "Medium"; 

 
else  return "Low"; 
--&gt;

Hope that helps someone.

Suggest an answer

Log in or Sign up to answer