How to Populate Day in a Custom Field based on Date Picker Custom Field Value in JIRA

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

The purpose of this article is to show how to automatically populate a custom field based on the chosen date from a Date Picker custom field. This can be done by using a third-party plugin; ScriptRunner for JIRA.

ℹ️ This configuration was tested on JIRA 6.4.4 using ScriptRunner 3.0.16

Solution

The information in this page relates to customisations in JIRA. Consequently, Atlassian Support cannot guarantee to provide any support for the steps described on this page as customisations are not covered under Atlassian Support Offerings. Please be aware that this material is provided for your information only and that you use it at your own risk.

Also, please be aware that customisations done by directly modifying files are not included in the upgrade process. These modifications will need to be reapplied manually on the upgraded instance.

  • Make sure you have ScriptRunner for JIRA plugin installed in your JIRA. If you don't have the plugin installed, please refer to Installing Marketplace apps to install ScriptRunner for JIRA.

  • Adding a Custom Field with type Date Picker. Place it on the "Create Issue Screen". This field will take input from users to get the date value. In this example, the name of the custom field is "Test Date".

  • Adding a Custom Field with type Scripted Field. The custom field type Scripted Field is provided by ScriptRunner for JIRA so you'll need to install ScriptRunner before adding this field. Do not place this field on any screens as the purpose of this field is being auto-populated based on the value of the "Test Date" field.

  • Run the following SQL query against JIRA's database to return the custom field ID:

    1  select id,cfname from customfield;

    In this example, the results we get are:

    1 2 3 4 5 6 7 8 id | cfname -------+----------------------- 10100 | Customer Request Type 10101 | Request participants 10102 | Time to resolution 10005 | Test Date 10006 | Test Day (5 rows)

    ℹ️ In our example above the Custom field ID for "Test Date" is 10005.

  • Navigate to Add-Ons > Script Fields. Notice that the "Test Day" custom field will be available in Scriptrunner Script Fields. Click on "Edit" to add the JavaScript from below.

  • Choose the option "Text Field (multi-line)" as the "Template" and paste the following Javascript in as a "Inline script".

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField ComponentManager componentManager = ComponentManager.getInstance() CustomFieldManager customFieldManager = componentManager.getCustomFieldManager() CustomField cf= customFieldManager.getCustomFieldObject("customfield_10005") def value = issue.getCustomFieldValue(cf) Calendar c = Calendar.getInstance() c.setTime(value) int dayOfWeek = c.get(Calendar.DAY_OF_WEEK) if (dayOfWeek == 1) return "Sunday" if (dayOfWeek == 2) return "Monday" if (dayOfWeek == 3) return "Tuesday" if (dayOfWeek == 4) return "Wednesday" if (dayOfWeek == 5) return "Thursday" if (dayOfWeek == 6) return "Friday" if (dayOfWeek == 7) return "Saturday"
Updated on April 2, 2025

Still need help?

The Atlassian Community is here for you.