Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Calculate how many days a issue is open

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

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)....

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

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

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

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

326 views 9 7
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you