Hi,
I have 2 date fields, 1. Acknowledged time 2. Resolved
With 2 script fields 1. On hold time 2. Time to resolution
With documentation for scripted fields i am able to get total on hold time and time to resolution (difference between acknowledged time and resolved)
On hold time template - Duration
Time to resolution script uses - Number as template.
Time to resolution includes on hold time also.
Wanted to know how to exclude onhold time from time to resolution. Can any one please help.
Below is the script used for Time to resolution,
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import java.util.Date
import java.sql.Timestamp
import java.time.temporal.ChronoUnit
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def lowerdatecustomfield = customFieldManager.getCustomFieldObjects(issue).find { it.name == "Acknowledged Time" }
if (!lowerdatecustomfield) {
log.info "Could not find one ore more of the provided custom fields"
return null
}
def higherDateValue = issue.resolutionDate as Timestamp
log.warn higherDateValue
def lowerDateValue = issue.getCustomFieldValue(lowerdatecustomfield) as Timestamp
log.warn lowerDateValue
//return higherDateValue.getTime() - lowerDateValue.getTime()
// Transform both values to instants
def lowerDateInstant = lowerDateValue?.toInstant()
def higherDateInstant = higherDateValue?.toInstant()
// Change the chrono unit to obtain the difference in other time unit.
final chronoUnit = ChronoUnit.(MINUTES)
// Calculate the difference between the lower and the higher date.
lowerDateInstant && higherDateInstant ? chronoUnit.between(lowerDateInstant, higherDateInstant) : null