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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.