Hi there fellows,
This one is breaking my head ;-)
I have this custom text field which has the following formula:
<!-- @@Formula:
String critical = "Critical"; // this variable has a string value of Critical
String high = "High"; // this variable has a string value of High
String medium = "Medium"; // this variable has a string value of Medium
String low = "Low"; // this variable has a string value of Low
String verylow = "Very Low"; // this variable has a string value of Very Low
String probability = (String)issue.get("Risk probability"); //This field is a Select List (single choice) from 5 possible entries.
String consequence = (String)issue.get("Risk consequence"); //This field is a Select List (single choice) from 5 possible entries.
if (probability == critical)
return "The same values:" + probability;
else
return "Field Value:|" + probability + "| != constant value:|" + critical + "|";
-->
When the calculation executes, it always result in FALSE
The following script has the same outcome:
<!-- @@Formula:
String critical = "Critical"; // this variable has a string value of Critical
String high = "High"; // this variable has a string value of High
String medium = "Medium"; // this variable has a string value of Medium
String low = "Low"; // this variable has a string value of Low
String verylow = "Very Low"; // this variable has a string value of Very Low
String probability = issue.get("Risk probability").toString(); //This field is a Select List (single choice) from 5 possible entries.
String consequence = issue.get("Risk consequence").toString(); //This field is a Select List (single choice) from 5 possible entries.
if (probability == critical)
return "The same values:" + probability;
else
return "Field Value:|" + probability + "| != constant value:|" + critical + "|";
-->
What am I missing? Or do I need to use another approach?
Hi,
this is likely because you are using the "==" operator to compare Strings. This would be valid in Groovy, but in Java (and BeanShell, which is derived from Java), the "==" operator returns true only if the two operands are one and the same. To test for String equality, you must use the equals() method:
"a".equals("a")
returns true, but:
"a" == "a"
returns false (because the two strings are two different Java objects, even though they contain the same characters).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.