Scriptrunner, trying to get first time in Status

Taylor Huston January 23, 2020

I'm trying to create a scripted field to show the first time an issue enters a specified Status, in this case "In Progress". Scriptrunner has example code to accomplish this exactly:

 

package com.onresolve.jira.groovy.test.scriptfields.scripts

import com.atlassian.jira.component.ComponentAccessor

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def created = changeHistoryManager.getChangeItemsForField(issue, "status").find {
it.toString == "In Progress"
}?.getCreated()

def createdTime = created?.getTime()

 

I've set the template to Date Time, and in the Script field dialogue if I preview an issue key it seems to be returning properly (16/Jan/20 12:03 AM for example), but if I then go look at that same issue directly it just says 'Invalid date'.

screenshot-jira.int.aurora.tech-2020.01 (1).png

What am I missing?

1 answer

1 accepted

1 vote
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 23, 2020

This works for me using just the created date (don't convert to time).

Have you set the searcher to "Date Time Range" in the field edit screen?

Also, I generally have a philosophical problem with repeatedly calculating a field to obtain a value that will be set once and never changed. That seems like a lot of compute cycles over time.

Instead, I would prefer to use a script listener or workflow post action and SET the value of the field when the status changes to in progress.

Leonard Chew
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.
January 24, 2020

Thumbs up to the suggestion on using a postfunction (or Script Listener) in combination with a static Custom Field to store the value.

Every scripted field consumes performance, and if you can avoid that (one-time-event vs. calculating every time), it is wise to do so.

Taylor Huston January 24, 2020

That worked, though it created a completely different issue XD.

Suggest an answer

Log in or Sign up to answer