Calculate how many days a issue is open

David Lockhart July 21, 2016

I am trying to have a custom field show how many days a issue has been open. I am using the script runner and created a script field. I am trying to find current date - created date for the days open. Here is the script  

import com.atlassian.core.util.DateUtils

DateUtils.getDurationString(((new Date().getTime() - issue.getCreated().date) / 1000 / 3600 / 24 ) as long)

But the date is not showing up correctly. 

 

I also want to exclude issue that are in a closed status here is what i have tried to add 

import com.atlassian.core.util.DateUtils


def Status = issue.getStatusObject();
if (Status == Closed) {
return null;
}
DateUtils.getDurationString(((new Date().getTime() - issue.getCreated().date) / 1000 / 3600 / 24 ) as long)

but it comes back with an error of No such property: Closed for class: Script7* (* this number keeps growing when you press preview). 

 

This is so i can use the field in a gadget on the dashboard. 

4 answers

1 vote
Bryan McMillan July 21, 2016

David,

I created a calculated field called "Days Open" with the following in the description field:

<!-- @@Formula: issue.get("resolutiondate")!=null ? null : ((new Date().getTime()) - issue.get("created").getTime()) / 1000 / 3600 / 24 -->

 

So, once the Issue is resolved this field is blank (i.e., empty) so it won't show.  I am running JIRA 6.3.13.

 

Regards,


Bryan

Maria Saez
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 30, 2021

What custom field would be used to create a Days Open field?

Paul Warkentin April 23, 2024

Hi Bryan, this is exactly what I am looking for. However, I asked my Administrator to create this calculated field and he could not find the option in any custom or other field options. Can you detail out where/how to create this calculated field in Jira? Thanks much!

Paul

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 23, 2024

Welcome to the Atlassian Community @Paul Warkentin 

You need to have installed an app to be able to do this.  Bryan is using the JSU app, and I think it's on Server/DC, so it might not be valid for you, because I don't know if you are on DC or Cloud, or if you have something like JSU or Scriptrunner, or another automation app.

Paul Warkentin April 24, 2024

Thanks for the response! We've got a cloud version. Was hoping to avoid paying for an App. Frustrating, something so simple I can do by exporting and Excel, shouldn't be this hard. Thanks again.

1 vote
Thanos Batagiannis _Adaptavist_
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.
July 21, 2016

Hi David,

Did you try the similar example in the documentation. First of all the error you are getting is because you misses the quotes in your status comparison, should be

if (Status == 'Closed') {
return null;
}

Also I do not know your exact requirements but I would suggest to use the statusCategory instead of Status. Also in your example, if I move the issue to a Closed status for 3 day and then reopen it, then in your script the result will not be valid (because now the issue is open but it was closed for 3 days)....

0 votes
David Lockhart July 25, 2016

I tried what you suggest again Bryan and it works. Thanks. Not sure why it did not work before. 

0 votes
David Lockhart July 22, 2016

Bryan,

when i create either a calculated Date/Time Field, Calculated Number Field then add the line that into the description. I go into the ticket click edit and then save to update the issue. It still does not show up. So i click admin then where is my field. I find the custom field and it gives me a message The field 'Day' does not have value for issue (issue ticket #) and will not be displayed on the view issue page. Set value for that field so that it shows up.

 

Dave

Suggest an answer

Log in or Sign up to answer