A Calculated Date/Time custom field type represents a |
To add a Calculated Date/Time custom field type to your instance:
Issues - > Custom fields.
Add custom field
.Advanced
in the left panel.Calculated Date/Time Field type
and select it.Next
.Create
Configure
and create a formula (explained below) for the field.If you have upgraded from JMCF |
When creating a Calculated Date/Time custom field type, you can configure the Search template as
Using these searchers you will be able to search issues within a date/time range of values for that custom field. The default search template is Date/Time range searcher (Statistics by day). If you select “None” for the searcher, then you won’t see any reference to this field in the Issue Navigator search fields. Note that changing a custom field searcher requires a re-index.
Date/Time range searcher (Statistics by day/week/month/quarter/year) are custom statistics compatible searchers provided by JMCF that allow Date/Time type custom fields of Jira and JMCF to be used in the statistics gadgets. See here for more information.
Starting from 2.0.0 BeanShell has been replaced by Groovy in the JMCF add-on. Scripts written in BeanShell will work unchanged in Groovy except for some specific cases. |
To write a formula for the Calculated Date/Time custom field type;
Configure
Edit Groovy Formula
Save.
As documented on the Expected Value tab of the Groovy editor help, the Groovy formula must return either:
null
Examples of Groovy formula for a Calculated Date/Time custom field:
A Groovy expression returning a String containing a date+time. For example,
"11/Apr/18 2:00 PM" |
A Groovy expression returning a date object. For example, the current date
new Date() |
A Groovy expression returning a JodaTime object. For example, the current date
import org.joda.time.DateTime DateTime date = new DateTime(); |
A Groovy expression that references any field of the issue that returns a java.util.Date.
For example, referring the issue updated date/time.
issue.get("updated") |
A Groovy expression that includes arithmetic operators as well as any other Groovy operator, and Groovy method calls. For example, adding a specific number of days to the issue creation date.
issue.get("created") + 5 |
By default, the Calculated Date/Time custom field type value is displayed using Jira's default date format (if you leave the Date Format
to Default
). However, you can customize it. To select a format for a Calculated Date/Time custom field type value;
Configure
Click on Edit Date Format.
Date format
drop-down.Save.
By default, the Calculated Date/Time custom field type value is displayed using Jira's default date format (if you leave the Date Column Format
to Default
) in the tabular views. However, you can customize it. To select a format for a Calculated Date/Time custom field type value in the List views;
Configure
Click on Edit Date Column Format.
Date format
drop-down.Save.
For example, if you select the COMPLETE
option in the Edit Date Format/Edit Date Column Format
, and the value returned by the Groovy formula is Thu Jan 25 15:20:34 IST 2018
, then the value will be formatted to 25/Jan/18 3:20 PM
.
You can define a velocity template that will return the Html representation of the calculated custom field. Leave it empty to use the default template.
To write a velocity template for a Calculated Date/time custom field type value;
Configure
Edit Velocity Template
.Save.
You can use the following Velocity variables in the template:
$value
: the raw field value, a Date object$formattedValue
: the field value formatted according to the field configuration aboveFor example:
<div style="border: dashed"> $formattedValue </div> |
displays the date in a dashed box.
The Never show on Transition and Edit screens
option controls whether the calculated Date/Time custom field can appear on transition and edit screens. If you select this option, the field will not be visible on any Edit or Transition screen, even if it is added to the screen.
You can access this field using any of the following getters of the Issue interface
get("Your custom field name") or get("customfield_xxxxx")
that returns a
Timestamp
getAsString("Your custom field name")
or
getAsString("customfield_xxxxx")
that returns a String
representing a date+time