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

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

 

 

Advertisements
Posted by:.

Leave a Reply

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

WordPress.com Logo

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

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s