In this example we explain how to create a Date-time scripted customfield using Adaptavist Scriptrunner for Jira Server.

First create a customfield of type “Scripted field

Captura de pantalla 2018-12-10 a las 20.21.57

After this, go to “Script Fields” in Jira

Captura de pantalla 2018-12-10 a las 20.20.16

Select “Add New Item” and then “Custom Script Field

Captura de pantalla 2018-12-10 a las 20.22.24

Select in Template “Date

Captura de pantalla 2018-12-10 a las 20.24.42

And add an inline script that returns a Date.

For example, in this script we obtain the Date of the parent ticket (called Movement Date) if the type of Issue is “Mover External” or “Mover Internal” and the scripted customfield will be shown in the Subtasks (as calculated field):

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueFactory
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.issue.customfields.CustomFieldType
import com.atlassian.jira.issue.customfields.*
import com.atlassian.jira.issue.CustomFieldManager
import java.text.SimpleDateFormat
import java.sql.Timestamp
import java.text.DateFormat
import java.util.Date
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
String value2 = issue.getParentObject()?

if ( value2 == "Mover Internal" || value2 == "Mover External") {
return issue.getParentObject()?.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName('Movement Date'))

Probably when you run the code you will get something like:

“always returns $datePickerFormatter.format($value)”

The problem is the “Searcher“… just change it! Click on “Free text searcher” and change it for “Date Time range picker“. That’s all!

Captura de pantalla 2018-12-10 a las 20.32.52


Captura de pantalla 2018-12-10 a las 20.33.17

After this probably Jira must be REINDEXED! 

Finally remember to restrict the field correctly to the Issuetypes and projects you want. (Configure the context of the customfield)

Captura de pantalla 2018-12-10 a las 20.30.35

By MrAddon



Posted by:.

2 replies on “Date Scripted Field example using Scriptrunner for Jira Server

  1. Thanks for this. It was really helpful.
    I have used your process to capture closed date for issues in a project with missing Resolution Dates.
    I’ve fixed the underlying issue with the Resolution Date but was wondering if you know of a way that i can now copy the Date Closed scripted field values into the Resolution Date field to back fill historical data?

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s