Random values in Search and ticket details for time-related field Edited


I've been trying to calculate the Cycle Time for our tickets and display the value as a custom field in Filters Search, Ticket Details, etc. When inspecting the value in the Preview in Script Runner, the value is always correct. However, in Filters Search, for example, the value randomly changes. This is related to the issues discussed here:


But I couldn't get it to work.

Here's the code:

import org.joda.time.DateTime
import org.joda.time.Days
import org.joda.time.LocalDate
import org.joda.time.Seconds
import com.atlassian.core.util.DateUtils
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def cycleStatuses = ["In Progress", "In Code Review", "Local UX/UI", "Local QA"]
def rt = [0]

boolean isInCycleStatus = false
DateTime nowTime = new DateTime(new Date().getTime())
changeHistoryManager.getChangeItemsForField (issue, "status").each {ChangeItemBean item ->
    long changeItemCreatedTime = item.created.getTime()
    int seconds = Seconds.secondsBetween(new DateTime(changeItemCreatedTime), nowTime).getSeconds()

    if (isInCycleStatus && (item.fromString in cycleStatuses) && !(item.toString in cycleStatuses)) {
        isInCycleStatus = false
        rt << -seconds

    if (!(item.fromString in cycleStatuses) && (item.toString in cycleStatuses)) {
        isInCycleStatus = true
        rt << seconds


Our Cycle Time is defined as time spent in any of the four statuses: "In Progress", "In Code Review", "Local UX/UI", "Local QA"

Is there a good way to query calculated fields on temporal data?

1 answer

Found a good explanation of the behaviour on Jamie's page:


Tried to disable the cache on this field and it seems to be working fine.

Suggest an answer

Log in or Join to answer
Community showcase
Alexey Matveev
Published Saturday in Jira

How to run Jira in a docker container

Everything below is tested on Ubuntu 17.10. I prefer to use Jira in a docker container because: 1. I can install Jira with a couple of commands. 2. I can start and stop Jira just by starting and s...

263 views 6 8
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot