JIRA & Groovy - Update Date Time of custom field based on comparison between two others.


Please forgive my ignorance in advance, I'm completely new to JIRA and Groovy expressions, having come from a front-end and PHP background... would really appreciate any assistance or pointers.



Create a POST-function that will automatically set the time and date of a custom field "Quote Status Updated On (Date Time Picker)", based on whether or not the custom field "Quote Status (Select List (Single choice) )" has changed.


I tried creating a new field "Previous Quote Status (Select List (Single choice) )" that will copy the last value of "Quote Status", with the intention of comparing the two, and updating "Quote Status Updated On" with the current Date Time if there has been a change.


1.  Copy Value From Field to Field (JMWE add-on)



Unfortunately the above does not successfully copy the value as needed, giving the following error on the view issue page:




2. Set Field Value to constant or Groovy expression (JMWE add-on) Function for this transition



The above obviously does not work since step 1 is does not copy the value, but I wonder if the syntax is correct?


If anybody has any resources, like a list of commands or expressions that are useful it would be a lifesaver, as the documentation I have does not seem comprehensive.

Thank you in advance!!

1 answer


you can achieve your goal with the following code, that you need to add as a post-function.

I assume, that the field "Quote Status" can be changed during the transition.


import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
import java.util.Date

// Manager
def cfm = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()

def issueBefTrans = issueManager.getIssueObject(issue.getKey())
if (issue.getCustomFieldValue(cfm.getCustomFieldObject("customfield_15007")) != issueBefTrans.getCustomFieldValue(cfm.getCustomFieldObject("customfield_15007"))) {
 cf_quoteStatusUpdatedOn = cfm.getCustomFieldObject("customfield_15008")
 cf_quoteStatusUpdatedOn.getCustomFieldType().updateValue(cf_quoteStatusUpdatedOn, issue, new Timestamp(new Date().getTime()))

Don't forget to adjust the customfield IDs to your environment.
'Quote Status' has the ID 15007
and 'Quote Status Updated On' has the ID 15008 in my environment.


This post-function has to be executed first during your transition, because the variable 'issue' holds the current fields incl. the values in screen. Whereas the variable 'issueBefTrans' holds all values before the transition. But this is only true, if the script will be executed first before the actual transition will be performed.

I don't know what documentation you use, but these sources offer everything you need:
and the official API:
https://docs.atlassian.com/jira/7.3.1/ (Our current JIRA version is 7.3.1)
Here is the list to all API versions:

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,173 views 5 10
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