Hi There! I'm brand new to Groovy Scripts but very familiar with Jira Server.
I'm using Jira Server v7.10.1. I am trying to implement a script post-function using ScriptRunner which will update my custom field for Time Stamp In Progress with the date and time that the transition from Create to In Progress occurs.
I've been scouring the Atlassian Community posts, and am currently testing out the script below. We are using Jira Business, not Software, so we do not have Component Manager declared. This may not be a concern, but wanted to call it out!
The field I want to populate with the current date and time is Time Stamp In Progress (field ID 16882).
Any guidance would be very appreciated :) Thank you!
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import static java.lang.Math.*
import java.sql.Timestamp
// get current issue
Issue issue = issue
customFieldManager = ComponentManager.getInstance().getCustomFieldManager()
// Getting custom field value
cfFuncDate = issue.getCustomFieldValue( customFieldManager.getCustomFieldObjectByName("Time Stamp In Progress") )
// Getting custom field object
cfoFuncDate = customFieldManager.getCustomFieldObjectByName("Time Stamp In Progress")
// get today's date
today = new java.sql.Timestamp(new Date().getTime())
// set value
if (!cfFuncDate)
issue.setCustomFieldValue(cfoFuncDate, today)
Hi @Tom Lister!
Without JSU - Suite Utilities for Jira, updating a custom issue field is not an option for a post-function. I do have ScriptRunner and determined how to write the Groovy Script.
import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def dateCf = customFieldManager.getCustomFieldObject("customfield_16920") // Date time fields require a Timestamp
issue.setCustomFieldValue(dateCf, new Timestamp((new Date()).time))
(Update the bold 16920 with the timestamp's field ID - you can find the field ID on the Custom fields page by clicking the gear and hovering over Configure. Check the URL populating at the bottom of the screen for the field ID. It takes a second to populate.)
5. Save your post-function.
Great, thanks. This was really useful to update a date-time field when it is empty.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you should be able to do this by using a post function to set custom field value and using %%CURRENT_DATETIME%%
See similar post here
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Tom Lister & @Lauren Robinette I think the suggestion you make is valid and works ... but only for new issuetypes that use this transition. It doesn't address how to update/fix previous values
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Richard Bone @Lauren Robinette
I think the only way to address that is to run a groovy script over the issue history. Below is an example of a scripted field I wrote to retrospectively find the date of the first transition. This is an example of the logic you would have to work into an update script.
package com.onresolve.jira.groovy.test.scriptfields.scripts
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
List<ChangeItemBean> created = changeHistoryManager.getChangeItemsForField(issue, "status").sort { it.getCreated() }
ChangeItemBean change
def createdTime
if (created)
{
change = created.first()
createdTime = change.getCreated()
}//.first()
createdTime ? new Date(createdTime.getTime()) : null
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.