Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Scripted field to display time to resolution excluding on hold time

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

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

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

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
TAGS
Community showcase
Posted in Jira Software

Presenting the "Best of 2020" Jira Software roundup!

Catch up with Atlassian Product Managers in our 2020 Demo Den round-up! From Advanced Roadmaps to Code in Jira to Next-Gen Workflows, check out the videos below to help up-level your work in the new ...

7,104 views 8 28
Join discussion

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