Formula field - script field

Field formula.

  • This field runs a formula(script) on the server to calculate the value. Now the field supports JavaScript Syntax in the future there will be support for other programming languages and templates.

The calculated field. The value of this field is the result of the formula. The value can be further processed before display.

Formula fields differ in value type.
Currently available types are: number, string, date.

For each type of field, you can connect a search engine to work with the field through JQL.
For numerical formulas, an additional time search engine is available.

Field settings include three parts.

1 - The formula for calculating the value.

This value will fall into the search index and should correspond to the selected field type.

Here you specify how to calculate the value.
JavaScript syntax is used.
In the formula (script), the following parameters are available for work:

  • issue - java class see documentation.

  • a list of custom field values ​​available through the variable cfValues ​​[xxxxx] - xxxxx is the numeric id of the custom field. With a formula, the values ​​of custom fields are cast to a string.

""+ issue.assignee + ": " + issue.key + " - " + issue.summary

You can use the functions

function calc(){ return cfValues[10011] / cfValues[10010] } calc()

2 - Formula for preparing data for display

Available Variables:

  • issue

  • cfValues

  • formulaValue - value of formula

This formula allows you to further process the value of the previous script before display.
For exam:

In step 1, you can calculate the time in seconds.

In this step I use JavaScript to format the value.

function timeFormat(sec_num) { var hours = Math.floor(sec_num / 3600); var minutes = Math.floor((sec_num - (hours * 3600)) / 60); var seconds = sec_num - (hours * 3600) - (minutes * 60); if (hours < 10) {hours = "0"+hours;} if (minutes < 10) {minutes = "0"+minutes;} if (seconds < 10) {seconds = "0"+seconds;} return hours+':'+minutes+':'+seconds; } timeFormat(formulaValue)

3 - Html formatting the result

if specified, then this html will be displayed as the value of the field. In the indices, this will be the value of formula 1.