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

Scriptrunner, trying to get first time in Status Edited

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

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 Community Leader Jan 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.

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

Suggest an answer

Log in or Sign up to answer
TAGS

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