Create a calculated field showing a percentage

Alastair Batchelor May 7, 2015

Hi all, I would appreciate it of someone could help me here. I'm completely new to JIRA and have no background as a user. I'm sure what I'm asking is actually fairly simple but I cant get it to work. 

Essentially I have two number fields and I want to create a third which shows a percentage of the two. So simply: 

 

Formula.JPG

 

I have attempted this using a calculated number field and some "script":

<!-- @@Formula: (issue.get("customFieldId=10427") &divide; issue.get("customFieldId=10007") : 0)–>

 

This has not worked and even if it had I'm not sure it would show a percentage anyway.

 

I understand I could use a scripted field which I have the add in to do but I don't know where to start with that.

 

Help much appreciated smile 

 

2 answers

0 votes
Junaid Shah
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.
May 7, 2015

Have you tried using a scripted field? I use that for a lot of calculations, and setting it as a text would allow you to add the % symbol as well.

Its with the Script Runner Plugin: https://jamieechlin.atlassian.net/wiki/display/GRV/Scripted+Fields

Here you can set your custom fields but using getCustomFieldValue("Custom Field Name")

and then perform the calculations you want and then returning the answer, if you need the percentage sign you can set it to return as a text searcher have something like

 

return "% " + answer

Which would end up something like this that you can use:

try{
//Retrieve two dates
w = getCustomFieldValue("Custom Field Name 1")
x = getCustomFieldValue("Custom Field Name 2")

//If Statement to check for nulls
if(w &amp;&amp; x != null){

//Calculating and saving answer
double answer = w/x as double

//displaying(returning) the answer
return answer
}
}
catch(Exception e)
{
}

If you'd like to do this through a post function then a post function is available called "Mathematical or date-time expression calculator " Through the plugin JIRA Workflow Toolbox, here you can calculate as well using different fields.

Junaid Shah
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.
May 7, 2015

I'd like to add that the answer I've done is only dividing two fields which contain numbers, if you want to do a percentage calculation then e.g You may calculate something like double difference = w-x as double double division = difference/w as double double answer = division*100 as double return answer this for example will give you the difference between w and x in a percentage.

0 votes
Arthur Gonçalves
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 7, 2015

Hey there,

I recommend you to use the add-on JIRA Misc Custom Fields to achieve this. Please take a look on their documentation at the following link:

https://innovalog.atlassian.net/wiki/display/JMCF/JIRA+Misc+Custom+Fields

 

--Arthur Gonçalves

Alastair Batchelor May 7, 2015

Hi Arthur, thanks for this. This is where I actually referenced to do the first attempt at the HTML in my original question. Can you see anything wrong with what I had attempted because its not returning any values: <!-- @@Formula: (issue.get("customFieldId=10427") &divide; issue.get("customFieldId=10007") : 0)–>

Junaid Shah
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.
May 7, 2015

try this: <!-- @@Formula: (issue.get("customfield_10427") != null ? issue.get("customfield_10427") : 0) / (issue.get("customfield_10007") != null ? issue.get("customfield_10007") : 0) -->

Alastair Batchelor May 7, 2015

Hi Sy, that definitely gets values in the field so a step closed I'd say! Not a percentage though, will that have to be done through a scripted field as you have done below? I'll give that a shot

Suggest an answer

Log in or Sign up to answer