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'.
What am I missing?
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That worked, though it created a completely different issue XD.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.