Age of the Issue

Hi All-

We are trying to calculate the age of each issue created in Jira. For this we have created a custom field of type Script Field. I am new to groovy.

Can some one help me in getting the age of the issue (current time - created date).

Any help is much appreciated.

Thanks in Advance,

Venkat

2 answers

1 accepted

This is pretty straightforward:

import com.atlassian.core.util.DateUtils

DateUtils.getDurationString(((new Date().getTime() - issue.getCreated().time) / 1000) as Long)

However, it may not do what you expect, as the value for a field is calculated at the time an issue is displayed, or updated. It's not updated in realtime.

NB - the code is suitable for the text template.

Hi Jamie,

Thank You.

How can we do issue.getresolutionDate().time - issue.getCreated().time? Is that correct to plug into new Date().getTime() - issue.getCreated().time?

NVM...went a different route

@Jamie Echlin [Adaptavist] : how to get  defect age on basis of following condition

1. if defect is closed:  created date - closed date ? 

if defect is not close

current date - created date 

how to put this condition ?

This works great a displaying the age, but when you add the "Age" column to a list of issues, it sorts alphabetically rather than by actual "Age". Any suggestion on how to account for the proper sorting?

Then you need to convert the age to days, use the number searcher, and the number template...

Hello @Jamie Echlin @David Webb Can you please help with the formula to get the number of days? I have changed the template to Number field and the searcher template to Number Searcher but it gives me incorrect output in terms of days and error DateUtils.getDurationString(((new Date().getTime() - issue.getCreated().time)/(1000*60*60*24)) as Long) Error==> The indexer for this field expects a java.lang.Double but the script returned a java.lang.String - this will cause problems. Any help will be appreciated Thanks!!

@Jamie Echlin [Adaptavist]

getDurationString returns something like "3 weeks", so if that's what you want you need to change the indexer, probably change it to None.

Changing searcher to None and selecting Custom Template with a $value field works BUT I can't get it to parse down to days.

 

import com.atlassian.core.util.DateUtils

DateUtils.getDurationString(((new Date().getTime() - issue.getCreated().time) / (1000)) as Long)

This works, shows d,h,m

 

import com.atlassian.core.util.DateUtils

DateUtils.getDurationString(((new Date().getTime() - issue.getCreated().time) / (1000*60*60*24)) as Long)

wipes all values entirely

@Lacey - what are you trying to do here? Get some duration period in days?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

361 views 0 1
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