How can I get a calculated custom field to use integer values instead of character decimal values?

I've been trying to get a calculated text field to work (using the Innovalog Misc Custom Fields Add-On) without luck. I'm trying to evaluate the values in two custom fields and then return a value in the calculated text field.

From this page -<field_name>%29+in+scripts – I determined that my custom fields, both of type 'Select List (single choice)', return string values.

The first character in both fields is a number. I need to add the first character from each field and then based on the sum, return a string of "High" (>8), "Medium" (>4), or "Low".

I have tried so many different approaches and I continue to see the result of my addition to be the sum of the decimal values of the numbers, not the sum of the integers. For example, if both fields start with "1", the result of the addition is 98 (NOT 2) - because the decimal value of character "1" is 49. Likewise, if one of the fields starts with "1" and the other starts with "2", then the sum is 99 (NOT 3).

This is the most recent code that I have tried:

Calculated value to illustrate relative risk, based on Risk Likelihood and Impact values.
<!-- @@Formula:

if (issue.get("Likelihood")==null || issue.get("Risk Impact")==null || issue.get("Likelihood")== "None" || issue.get("Risk Impact")== "None")
    return "n/a";
else {
    int iLikelihood;
    iLikelihood = Integer.valueOf(issue.get("Likelihood").charAt(0));

    int iProjectRisk;
    iProjectRisk = Integer.valueOf(issue.get("Risk Impact").charAt(0));

    int iSum;
    iSum = Integer.valueOf(iLikelihood) + iProjectRisk;

    if (iSum > 7)
        return "High";
    else if (iSum > 4)
        return "Medium";
        return "Low";


1) I tried to use Integer.parseInt() to save the first character of each field as an integer :
    int iLikelihood;
    iLikelihood = Integer.parseInt(issue.get("Likelihood").charAt(0));
but got the following error :
    "Error in method invocation: Static method parseInt( char ) not found in class'java.lang.Integer'".
so I switched to using Integer.valueOf()
    int iLikelihood;
    iLikelihood = Integer.valueOf(issue.get("Likelihood").charAt(0));

2) I tried to store the first character of each field in a string variable (since the source field is of type String) :
    String sLikelihood;
    sLikelihood = issue.get("Likelihood").charAt(0);
but got the following error :
    "Variable assignment: sLikelihood: Can't assign primitive value to object type:class java.lang.String"
so switched to storing the first character in an integer variable
    int iLikelihood;
    iLikelihood = issue.get("Likelihood").charAt(0);

I tried many different combinations of using the Integer.valueOf() method to get the variables into integer format, but they always resulted in the sum being 98 or higher.

I've been working on this for over 2 days and just can't find any permutation that works! Any help that can allow me to get actual integer addition to work would be greatly appreciated!! (In the mean time, I changed my if-else rules to check for > 100 and > 103 (instead of > 4 and > 7), which is giving me the final result that I'm looking for - but isn't really the cleanest way to do this.)

Thank you!

0 answers

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

172 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you