...
Formula syntax
The formula is written using the BeanShell language, and should be included in the field description inside an html comment (so that it remains invisible when showing the field description), preceded by the following keyword: @@Formula: (note the colon at the end). For example:
...
Code Block |
---|
issue.get("<field_ID_or_ID>Name>") |
where <field_ID_or_ID> Name> is either a built-in JIRA field ID or a or custom field ID (the latter in the form customfield_nnnnn), or a field name. See this page for details.
...
Info | ||
---|---|---|
| ||
If the calculated field does not show up on the view issue screen, you must make sure the formula isn't raising an error. For that, you must look at the end of the JIRA log file (atliassian-jira.log) right after displaying the issue (displaying an issue will always force calculated fields to be re-calculated). |
Example
Adding two fields
To add two custom fields, such as "Business Value" and "Technical Value" to get an "Overall Value":
Code Block | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
<! You can also include logging code into your script using the "log" object. For example:
|
Custom formatting
You can also specify custom formatting for the value of the Calculated Number field. In the Description field, add your formatting formula using the following syntax:
Code Block |
---|
<!-- @@Format: formula goes here --> |
The formula itself is a Java-style expression that can reference the value returned by the formula using the value variable. You can also use the numberTool object to format the number value:
Code Block |
---|
numberTool.format(value)
|
Example
...
We recommend you write to the logs using the "log.error()" method because ERROR-level logs are always written out to atlassian-jira.log (whereas DEBUG-level logs are filtered out by default). |
Example
Adding two fields
To add two custom fields, such as "Business Value" and "Technical Value" to get an "Overall Value":
Code Block |
---|
<!-- @@Format: if (value > 21) return "<img src='/images/icons/priority_trivial.gif'> "+numberTool.format(value); else if (value >= 10) return "<img src='/images/icons/priority_major.gif'> "+numberTool.format(value); else return "<img src='/images/icons/priority_blocker.gif'> "+@@Formula: (issue.get("customfield_10114") != null ? issue.get("customfield_10114") : 0) + (issue.get("customfield_10150") != null ? issue.get("customfield_10150") : 0) --> |
Custom formatting
You can also specify custom formatting for the value of the Calculated Number field. In the Description field, add your formatting formula using the following syntax:
Code Block |
---|
<!-- @@Format: formula goes here --> |
The formula itself is a Java-style expression that can reference the value returned by the formula using the value variable. You can also use the numberTool object to format the number value:
Code Block |
---|
numberTool.format(value);
-->
|
...
- Create a new custom field, choosing "Calculated Text Field" for its type.
- During step 2, in the Description field, include the calculation formula using the syntax described below.
- Re-index your data, as JIRA will kindly suggest you to.
Formula syntax
The formula should be included in the field description inside an html comment (so that it remains invisible when showing the field description), preceded by the following keyword: @@Formula: (note the colon at the end). For example:
Code Block |
---|
<!-- @@Formula: formula goes here --> |
You can naturally include the real description of the custom field as well. For example:
Code Block |
---|
This field represents the first 10 characters of the issue's summary field.
<!-- @@Formula: issue.get("summary").substring(0,10) --> |
The formula itself is a Java-style expression that can reference any issue field value, include Java operators, and Java method calls (such as the .substring(0,10)
example above). Access to issue field values is achieved by the following syntax:
Code Block |
---|
issue.get("<field_ID>") |
where <field_ID> is a built-in JIRA field ID or a custom field ID (in the form customfield_nnnnn). See this page for details.
You can also access the JIRA Issue object using the issueObject
variable.
Info | ||
---|---|---|
| ||
|
Note that you must make sure the formula returns a String, or null.
Info | ||
---|---|---|
| ||
If the calculated field does not show up on the view issue screen, you must make sure the formula isn't raising an error. For that, you must look at the end of the JIRA log file (atliassian-jira.log) right after displaying the issue (displaying an issue will always force calculated fields to be re-calculated). |
Exact Text Searcher (Statistics-compatible) (new in 1.5.6)
When creating a Calculated Text Field, you can choose between the standard Free Text Searcher and the new Exact Text Searcher (Statistics-compatible). The latter should be used if you need either of the following:
- Be able to search issues based on the exact value of the custom field (i.e. use the "=" operator instead of the "~" operator)
- Be able to use the field in one of the statistics reports or dashboard gadgets
...
- Create a new custom field, choosing "Calculated Date/Time Field" for its type.
- During step 2, in the Description field, include the calculation formula using the syntax described below.
- Re-index your data, as JIRA will kindly suggest you to.
Formula syntax
The formula should be included in the field description inside an html comment (so that it remains invisible when showing the field description), preceded by the following keyword: @@Formula: (note the colon at the end). For example:
Code Block |
---|
<!-- @@Formula: formula goes here --> |
You can naturally include the real description of the custom field as well. For example:
Code Block |
---|
This field represents 10 days after the creation of the issue.
<!-- @@Formula: org.apache.commons.lang.time.DateUtils.addDays(issue.get("created"),10) --> |
The formula itself is a Java-style expression that can reference any issue field value, include Java operators, and Java method calls (such as the org.apache.commons.lang.time.DateUtils.addDays()
example above). Access to issue field values is achieved by the following syntax:
Code Block |
---|
issue.get("<field_ID>") |
where <field_ID> is a built-in JIRA field ID or a custom field ID (in the form customfield_nnnnn). See this page for details.
You can also access the JIRA Issue object using the issueObject
variable.
Info | ||
---|---|---|
| ||
|
Note that you must make sure the formula returns a java.util.Date, or null.
...
title | Debugging the script |
---|
...
|
Example
To display an icon to the left of the field value depending on the field value:
Code Block |
---|
<!-- @@Format:
if (value > 21)
return "<img src='/images/icons/priority_trivial.gif'> "+numberTool.format(value);
else if (value >= 10)
return "<img src='/images/icons/priority_major.gif'> "+numberTool.format(value);
else
return "<img src='/images/icons/priority_blocker.gif'> "+numberTool.format(value);
-->
|
Anchor | ||||
---|---|---|---|---|
|
- Create a new custom field, choosing "Calculated Text Field" for its type.
- During step 2, in the Description field, include the calculation formula using the syntax described below.
- Re-index your data, as JIRA will kindly suggest you to.
Formula syntax
The formula is written using the BeanShell language, and should be included in the field description inside an html comment (so that it remains invisible when showing the field description), preceded by the following keyword: @@Formula: (note the colon at the end). See Calculated Number Field above for details.
Note that you must make sure the formula returns a String, or null.
Exact Text Searcher (Statistics-compatible) (new in 1.5.6)
When creating a Calculated Text Field, you can choose between the standard Free Text Searcher and the new Exact Text Searcher (Statistics-compatible). The latter should be used if you need either of the following:
- Be able to search issues based on the exact value of the custom field (i.e. use the "=" operator instead of the "~" operator)
- Be able to use the field in one of the statistics reports or dashboard gadgets
Anchor | ||||
---|---|---|---|---|
|
- Create a new custom field, choosing "Calculated Date/Time Field" for its type.
- During step 2, in the Description field, include the calculation formula using the syntax described below.
- Re-index your data, as JIRA will kindly suggest you to.
Formula syntax
The formula is written using the BeanShell language, and should be included in the field description inside an html comment (so that it remains invisible when showing the field description), preceded by the following keyword: @@Formula: (note the colon at the end). See Calculated Number Field above for details.
Note that you must make sure the formula returns a java.util.Date, or null.
Custom formatting
You can also specify a date/time format for the value of the Calculated Date/Time field. In the Description field, add the name of the date/time format using the following syntax:
Code Block |
---|
<!-- @@Format: <format_name> --> |
where <format_name>
is one of the constants found here: https://developer.atlassian.com/static/javadoc/jira/reference/com/atlassian/jira/datetime/DateTimeStyle.html
...