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,364,966
Community Members
 
Community Events
168
Community Groups

Time in "Open" Status

Hi,

I have found the following code but I require some assistance to modify the code.

I wish to show the time that an issue is in the "Open" status but with the code, it is somehow adding the "Open" status and "In Progress" time together and not accurately showing the information.

How do I modify this to just show the "Open" time?

 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.history.ChangeItemBean;
import com.atlassian.jira.issue.Issue;
 
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
 
def statusName = "Open"
def createdDateDiff = System.currentTimeMillis() - issue.getCreated().getTime()
 
List<Long> rt = [0L]
 
rt << createdDateDiff
 
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")
changeItems.reverse().each {ChangeItemBean item -> item.fromString
 
 // Get the time passed since status change
 def timeDiff = System.currentTimeMillis() - item.created.getTime()
 
 // If the status change left our status, we want to subtract the time passed since then
 if (item.fromString == statusName) {
 rt << -timeDiff
 }
 
 // If the status change goes to our status, we want to add the time passed since then
 if (item.toString == statusName){
 rt << timeDiff
 }
}
 
def total = (rt.sum() as Long) / 1000
 
return Math.round(total) ?: 0
Thank you. 1.JPG

3 answers

1 accepted

0 votes
Answer accepted
Tansu Akdeniz Community Leader Aug 10, 2022

Hi @Drishti Maharaj 

It should calculate the duration in Open status. Because statusName = "Open" is given as a parameter in the code. To be sure, can you please go to one sample issue and look at the history and verify the duration in open status?

Also check "Total time this issue has been In Progress" section in this doc

Hello @Drishti Maharaj 

As an alternative, you can try the third-party addons. Such as Time between Statuses (server version) by SaaSJet.  Just set the "Open" status as Start and Stop timers and get the time in the "Open" status

Hope it helps.

Regards

0 votes
Bloompeak Support Marketplace Partner Aug 10, 2022

Hi @Drishti Maharaj

If you prefer to use a plugin, you can try Status Time Reports app developed by our team. It mainly provides reports and gadgets based on how much time passed in each status.

Here is the online demo link, you can see it in action and try without installing the app. For your case, you can have a look at Time in Status for Each Issue report.

  • This app has a dynamic status grouping feature so that you can generate various valuable reports as as time in status, time in assignee, status entry dates and status counts, cycle time and lead time, average/sum reports by any field(e.g. average in progress time by project, average cycle time by issue creation month).
  • You can search issues by Project, Issue Type, Status, Assignee, Issue Creation/Resolution Date(and any other Date field) and JQL Query.
  • Status durations are calculated according to the working calendar you define. Once you enter your working calendar into the app, it takes your working schedule into account too. That is, "In Progress" time of an issue opened on Friday at 5 PM and closed on Monday at 9 AM, will be a few hours rather than 3 days.
  • You can set different duration formats.
  • You can export reports in CSV file format and open them in MS Excel.
  • You can also add this app as a gadget to your Jira dashboards and reach “Status Time” from Issue Detail page.
  • You can enable/disable access to Status Time reports&gadgets and Issue Detail page per project, users, groups or project role.

If you are looking for a free solution, you can try the limited version Status Time Free.

Hope it helps.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events