Is there a way to persist the value of calculated custom fields on JIRA?

Felipe Reis
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.
April 1, 2013

Hello!

I have created a custom field which has its value calculated based on the date a transition happened. I would like to use this value on a report that reads data directly from JIRA's database.

I am aware that JIRA indexes the value of calculated custom fields and does not store it in the database. My question is if there is some workaround I could use in order to persist this data, somehow.

Cheers!

2 answers

1 accepted

1 vote
Answer accepted
Justin Shapiro
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.
April 2, 2013

If you are writing it then you can do it. I don't generally use calculated field types instead I use, for instance, a number field type and do my calculation in getValueFromIssue and then call updateValue before returning my calculated result. I'm sure you could do something similar.

Felipe Reis
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.
April 3, 2013

Thanks for your repply Justin.

Yes, it's a field I'm creating myself. I didn't understand what you mean by doing the calculation in the getValueFromIssue. If it's not a calculated field how can I perform a calculation?

Cheers!!

Justin Shapiro
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.
April 12, 2013
+---------+     +--------+     +------+     +--------+
| working | --> | review | --> | test | --> | closed |
+---------+     +--------+     +------+     +--------+
     |              |             |
      <------<------+<------<-----+
        Fail Review     Fail Test

Ok continuing my example if my workflow was as above, I would creeate a customfield call "Review Fail Count" and increment it each time that transition is followed. I would also create a "Test Fail Count" field and increment that for its transition. My pseudo calculated field wouyld be "Total Fail Count" where I would grab the values of the two previous fields and set my "Total Fail Count" field to that value and then return that result. All three fields are indexed and searchable through a number range searcher so I can query issues that failed review x number of time or test x number of times or total failures.

getValueFromIssue()

{

review = getCustomField("Review Fail Count").getValue(issue)

test = getCustomField("Test Fail Count").getValue(issue)

total = review + test

updateValue(total)

return total;

}

Felipe Reis
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.
April 15, 2013

Thank you for your thorough explanation :)

I have one (dumb) question though: where do I put this getValueFromIssue method?

Cheers!!!

Justin Shapiro
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.
April 16, 2013

you are overriding it in your new customfield

getValueFromIssue(final CustomField field, final Issue issue)

Abhishek Sharma April 23, 2018

Hi Justin,

 

Thanks for your answer. It indeed gives me some insight though em bit unclear about one last point that how is it updating your third custom field 'Total Fail Count'?

Do we have to write updateValue(x) function somewhere or it's a default Jira function provided and I just need to know how should I use it?

0 votes
Ricardo Rodríguez April 15, 2013

Hi Justin, I would like to know how to increase the value of a custom field with the transitions that you have in your workflow

Justin Shapiro
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.
April 16, 2013

i use a post function

Suggest an answer

Log in or Sign up to answer