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 total time a issue has been in open state

I m trying to show th total time a issue has been in open state. For that I m using a scripted field

and a modified script :

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 = "Open"
 
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))

Problem is the field allways show 0m. Can someone help?

5 answers

1 accepted

0 votes
Answer accepted

That's just example code, not really production quality. It doesn't work if the status you are interested in is the first one.

I just made an edit - https://gist.github.com/jechlin/10928320

I think the problem is that you should use item.created.getTime()

com.atlassian.jira.issue.history.ChangeItemBean.getCreated() returns java.sql.Timestamp so you should call getTime() to get milliseconds.

Hi Boris,

no that doesn t help scripted field still shows 0m.

Isn't "<<" a bit-operator? I don't think that works with collections/arrays. Try this instead:

rt.add(timeDiff)

<< is overridden for collections in groovy.

Is there a way to get total time since creation but not closed?  I really wouldn't want to have to add up all the time between transitions as I would not know each transition it goes through.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Happy New Year and Welcome New Marketplace Partner Program Partners!

Happy New Year! We hope you all had a safe and restful holiday season. 2020 was a unique year full of unforeseen events; however, as we enter the new year of 2021, we’re optimistic for the light at t...

641 views 7 23
Read article

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