Scripted field to display time to resolution excluding on hold time

Krithica G December 1, 2020

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

1 answer

0 votes
Bill Sheboy
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.
December 11, 2020

Hi @Krithica G 

If the "hold time" is also in minutes, why couldn't you just subtract that time also?  And perhaps, persist it in a custom field and update it so it is available for the subtraction.

Please note that by subtracting the value of "hold time", the result is no longer "time to resolution".  It would appear to be "working time to resolution".

 

If you are unable to solve this with scripted fields, consider using custom fields and scheduled automation rules (automation lite for Jira Server, or the full version).  You may learn more about the automation for Jira rules in this documentation:

https://confluence.atlassian.com/automation

 

Best regards,

Bill

Krithica G December 29, 2020

Hi,

Thanks.

On hold time is a duration field displays as 2 days 1 hour 30 minutes 15 seconds.

Time to Resolution field is displayed in minutes.

I want to know how to convert the duration into minutes so that it will be easy for me to compute working Time to resolution (excluding on hold time). 

Can anyone please help?

Thanks,

Krithica

Bill Sheboy
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.
December 30, 2020

Hi @Krithica G 

If you are doing this with automation rules (as I noted earlier), you can get minutes when the diff() is performed.  For example, {{issue.created.diff(issue.updated).minutes}}

For the scripting method, isn't the value already in milliseconds?  If so, you could just divide the value to get minutes: value / 1000  / 60

Suggest an answer

Log in or Sign up to answer