A Calculated (scripted) Text/Html custom field type displays text calculated using a Groovy script and supports HTML formatting tags. |
To add a Calculated (scripted) Text/Html custom field type to your instance:
Issues - > Custom fields.
Add custom field
.Advanced
in the left panel.Calculated (scripted) Text/Html Field
and select it.Next
.Create.
Configure
and create a formula (explained below) for the fieldIf you have upgraded from JMCF |
The Disable Value Collapse
option controls whether the Calculated (scripted) Text/Html custom field type can be collapsed on the issue view screen or not. If this option is selected, the collapse toggle is removed on the issue view screen, and the user cannot collapse the custom field value.
The collapse toggle is visible for the custom field value on the issue view screen only for texts exceeding 128 characters. It is not visible for texts with less than or equal to 128 characters, irrespective of the |
When creating a Calculated (scripted) Text/Html custom field type, you can configure the Search template as
Using these searchers you will be able to search issues either with a free text or the exact text for that custom field value. The default search template is Exact text searcher (Statistics-compatible)
. 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.
Exact text searcher (Statistics-compatible) is a custom statistics compatible searcher provided by JMCF that allows Text type custom fields of Jira and JMCF to be used in statistics gadgets. 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.
Starting from 2.0.0 BeanShell has been replaced by Groovy in the JMCF add-on. Formulae written in BeanShell will work unchanged in Groovy except for some specific cases. |
To write a formula for the Calculated (scripted) Text/Html custom field type;
Configure.
Edit Groovy Formula.
Save.
As documented on the Expected Value tab of the Groovy help editor, the Groovy formula must return either a String with or without HMTL formatting tags or null.
Note that the Groovy tester shows the HTML-rendered value of the result when tested against an issue.
Examples of Groovy formula for a Calculated (scripted) Text/Html custom field:
A simple String:
"JMCF 2.0.0" |
A String with HTML formatting tags
"<i> The latest version of JMCF is <b>2.0.1</b> </i>" |
returns The latest version of JMCF is 2.0.1
A Groovy expression to reference any field of the issue that returns a String, for example, the Summary of the issue.
issue.summary |
A Groovy expression that includes Groovy operators such as the String concatenate.
issue.get("summary") + textutils.noNull(issue.get("description")) |
A Groovy expression that includes Groovy method calls, for example, to replace a specific String using the replace()
method
issue.get("description").replace('Cloud','Server') |
A Groovy expression with a wiki markup or reference to any field of the issue that has a wiki markup (like Environment). For example, calculate and display the Environment and severity of the issue
"Impacts on Environments: " + issue.get("environment") + "\n" + "Severity of the issue: " + issue.get("Severity") |
will be displayed as Impacts on Environments: *Production* - _Stage 1_ Severity of the issue: Critical
However, to display the issue without ignoring the wiki markup:
You can use the getAsHtml()
method to access the field value as Html:
"Impacts on Environments: " + issue.getAsHtml("environment") + "\n" + "Severity of the issue: " + issue.get("Severity") |
or create and configure a Calculated (scripted) Wiki Text type custom field to support wiki-style formatting (needs "Wiki Style Renderer" configured) with the formula:
"Impacts on Environments: " + issue.get("environment") + "\n" + "Severity of the issue: " + issue.get("Severity") |
and the field value will be displayed as:
|
You can define a velocity template that will return the Html representation of the calculated custom field on the issue detail view, in addition to the formatting provided in the custom field value. Leave it empty to use the default template.
To select a format for a Calculated (scripted) Text/Html 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 String$formattedValue
: a StringFor example:
<font color="red"> $value </font> |
You can define a velocity template that will return the Html representation of the calculated custom field on the search list view, in addition to the formatting provided in the custom field value. Leave it empty to use the default template.
To select a format for a Calculated (scripted) Text/Html custom field type value;
Configure
Edit List View Velocity Template
.Save.
You can use the following Velocity variables in the template:
$value
: the raw field value a String$formattedValue
: a StringFor example:
<font color="red"> $value </font> |
The Never show on Transition and Edit screens
option controls whether the Calculated (scripted) Text/Html 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")
or
getAsString("Your custom field name")
or
getAsString("customfield_xxxxx")
that returns a String.