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,557,893
Community Members
 
Community Events
184
Community Groups

Groovy: show time this issue In-Progress status (Not Total)

Hi!
How i can show up days count of last transition.
I dont need calculate total, this value should be refreshable and setted per new transition.

import com.atlassian.core.util.DateUtils
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.history.ChangeItemBean

def componentManager = ComponentManager.getInstance()
def changeHistoryManager = componentManager.getChangeHistoryManager()

def inProgressName = "In Progress"

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

    def timeDiff = System.currentTimeMillis() - item.created.getTime()
    if (item.fromString == inProgressName) {
        rt << -timeDiff
    }
    if (item.toString == inProgressName){
        rt << timeDiff
    }
}

// NOTE: doesn't show anything if less than 60 seconds
DateUtils.getDurationString(Math.round(rt.sum() / 1000))


Can some one help me?

8 answers

1 vote
JamieA
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.
Apr 05, 2016

OK:

import com.atlassian.jira.component.ComponentAccessor

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def items = changeHistoryManager.getChangeItemsForField (issue, "status").reverse()

if (items) {
    return ((new Date().time - items.first().created.time) / 1000) as Long
}
else {
    return ((new Date().time - issue.getCreated().time) / 1000) as Long
}

Searcher: Duration

Custom template:

#if ($value)
	$jiraDurationUtils.getFormattedDuration($value)
#end

You are the best, thanks! This working for me =) 

@Jamie Echlin [Adaptavist] hi!

I solve this via:

image2016-4-11 17:56:36.png 

 

And Searcher: 

image2016-4-11 17:56:58.png 

Can you help me a little bit?
Now current field show me a seconds, 

how i can convert it to time? (minutes/hours/days?)

JamieA
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.
Apr 11, 2016

getDurationString should return you a properly formatted duration... 

Best thing is to return a Long then use the template as I originally recommended. I don't think the search will work though. Try all this with no searcher.

 I'll tried this all with searcher "None" and with sting/long combinations:

    $jiraDurationUtils.getDurationString($value) 

     $jiraDurationUtils.getFormattedDuration($value)

    $jiraDurationUtils.getDaysDurationFormatter($value)

    $jiraDurationUtils.getHoursDurationFormatter($value)

    $jiraDurationUtils.getPrettyDurationFormatter($value)

    $jiraDurationUtils.getShortFormattedDuration($value)

It doesnt worked in JIRA 6.4.5 and Script Runner v 3.1.4

Nevertheless thank you @Jamie Echlin [Adaptavist].

Hi!

something goes wrong...

 image2016-4-7 10:24:50.png

JamieA
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.
Apr 07, 2016

Change the searcher for the field to Duration, as I said in my answer. If you don't see Duration you might be using an older version, if so which one?

Current versiob is: v 3.1.4
JamieA
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.
Apr 07, 2016

Set the searcher for the field to None then, but it's best if you can upgrade so you can using the duration indexer. You didn't answer the question about whether it was there by the way.

Hi @Jamie Echlin [Adaptavist] 
I did what you recommended, so i can see now is that it is:$jiraDurationUtils.getFormattedDuration($value) 

Untitled111.jpg 

@Jamie Echlin [Adaptavist] Hi!
Please, clarify.

Jamie, yes.
Could you add more details here, sorry but i dont know how realise it via groovy code, can you advise please?

0 votes
JamieA
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.
Apr 05, 2016

You just want the time in the current status? Then you just need to subtract the first change item returned from the current date.

Hi Jamie,
Yes, you right.
This code show me total days. But i'm needed to show up days according each transition to this status (not total).

For example (how this should work):
I changed my status from Open to In-Progress yesterday, and now i see 1 day,
I changed it status to on-hold, then i am again changed it to in-progress and now i see 1 min,

do you understand?

0 votes
JamieA
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.
Apr 04, 2016

Can you elaborate on "How i can show up days count of last transition". Why did you post that code, is that what you have tried?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events