The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
I am trying to calculate the time an issue is created until the time it is closed. I created a time date field (Closed Date) that is populate with the date the issue is closed in a post function. I found code that allows me to calculate the time to resolution and I am trying to make it work for closed also but can not figure out the how to pull in the custom date field. Any help would be much appreciated.
Using Script Runner Scripted Fields
This is the code I am using for Time to Resolution:
import
com.atlassian.core.util.DateUtils
def
resolvedNames = [
"Resolved"
,
"Closed"
]
def
timeDiff;
timeDiff = issue.getResolutionDate().getTime() - issue.getCreated().getTime()
}
else
{
timeDiff = System.currentTimeMillis() - issue.getCreated().getTime()
}
// NOTE: doesn't show anything if less than 60 seconds
DateUtils.getDurationString(Math.round(timeDiff /
1000
))
Community moderators have prevented the ability to post new answers.
You need to access the custom filed itself and retrieve the value for the issue.
Try this:
import com.atlassian.jira.issue.Issue; import com.atlassian.jira.ComponentManager; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.component.ComponentAccessor; .... def field = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(ClosedDate) def closedDate = (Date)issue.getCustomFieldValue(field); timeDiff = closedDate.getTime() - issue.getCreated().getTime()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You want to write the value of DateUtils.getDurationString
to the custom field, right? Try
return DateUtils.getDurationString(Math.round(timeDiff / 1000))
Or do you want to read from the custom field? Maybe this helps:
https://answers.atlassian.com/questions/284367
The code is from here: https://jamieechlin.atlassian.net/wiki/display/GRV/Scripted+Fields
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am actually trying to figure out how to perform this part
timeDiff = issue.getResolutionDate().getTime() - issue.getCreated().getTime()
I need the bold part to reflect the custom field I created called ClosedDate
I tried issue.getClosedDAte().getTime() but that did not work
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We are sharing mini new cloud roundups by use case to celebrate the Atlassian Marketplace's 10th Anniversary! This mini roundup is the fourth in a series of six. Check out others in the series based ...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.