JIRA: Update a Custom Field with Difference between Two Dates

Learn how to update a custom field with the difference between two dates in JIRA, using a Groovy script on your workflow transitions. This can be achieved using the ever-powerful ScriptRunner add-on, together with the custom Groovy script. This post details how this requirement can be achieved.


  • Information from JIRA
    • JIRA workflow to embed the script
    • The custom field name and its option IDs
  • ScriptRunner for JIRA
  • Groovy script to execute

Script to Calculate and Update Field with Difference between Two Dates

The script can be downloaded from my Bitbucket repo here: ValidateTwoDatesWorkflow.groovy @ Bitbucket

Configuration in JIRA

In the workflow for the project, I added a new Custom Script post function to the Resolve Issue transition:

update field with difference between two dates
Add a Custom Script to the list of post functions on the appropriate workflow.

Technology Consultant at ServiceRocket. Great knowledge in Atlassian JIRA. Blogger. Programmer. Anime Vector Artist.