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”

After this, go to “Script Fields” in Jira

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

Select in Template “Date”

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()?.issueType.name
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!

….

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)

By MrAddon






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?
LikeLiked by 1 person
Hello Ryan, take a look at this post: https://mraddon.blog/2019/04/07/is-there-a-way-to-change-the-resolution-date-in-jira/
Cheers!
LikeLike