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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,553,058
Community Members
 
Community Events
184
Community Groups

Time in Status - Script Runner - custom scripted field - Reset on status change

Edited
Steven Mustari
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.
Dec 03, 2019

The following code and variations has been circulating around on how to calculate a time in the template "duration" format for an issue. I have the code working but I believe it is setup to calculate a cumulative total of any time the issue has been in a status during it's lifecycle.

I'm attempting to create a version of this code that will only show the current instance of being this status (any status). So for instance:

  • Issue is created ->
  • Open (returns time in this instance of Open) ->
  • In Progress (returns time in this instance of In Progress) ->
  • Open (returns time in this instance of Open not adding the time from any previous instance)
  • In Progress (returns time in this instance of In Progress not adding the time from any previous instance)

Here is the code being utilized:

import com.atlassian.jira.component.ComponentAccessor

def changeHistoryManager = ComponentAccessor.changeHistoryManager
def currentStatusName = issue?.status?.name

def rt = [0L]
changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {item ->

def timeDiff = System.currentTimeMillis() - item.created.getTime()
if (item.fromString == currentStatusName) {
rt << -timeDiff
}
if (item.toString == currentStatusName){
rt << timeDiff
}
}
def total = rt.sum() as Long
return (total / 1000) as long ?: 0L

 I would like this data to retain the duration template if at all possible.

My thought is I need to get the last status change time here somehow, and eliminate the second if statement?

Thank you in advance!

1 answer

1 accepted

0 votes
Answer accepted
Steven Mustari
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.
Dec 10, 2019

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events