JavaScript calculated custom fields

This page describes advanced Jira and eazyBI integration. If you need help with this please contact eazyBI support.

JavaScript calculated custom fields are available starting from eazyBI version 3.1.0.

If you would like to pre-calculate and import in eazyBI additional calculated custom fields then

  • you can either use Jira Misc Custom Fields add-on and define Jira calculated custom fields (or use some other add-on that allows to define calculated custom fields),
  • or you can define calculated custom fields using JavaScript in eazyBI advanced settings as described further (and then they will be available just in eazyBI and not in Jira).

If you have larger number of Jira issues then it is better to import calculated custom fields and not to create calculated members with complex MDX formulas. Calculated custom fields are pre-calculated just once during Jira import and then saved in the eazyBI database and then eazyBI queries will perform much faster using pre-calculated data.

On this page:

Define calculated custom field in eazyBI advanced settings

You should define an additional custom field in the advanced settings with the following additional settings:

  • Use your own customfield_NAME custom field name where NAME is some unique descriptive name of your additional calculated custom field.
  • Add a name setting and specify a display name for this calculated custom field that will be visible in Jira import custom fields selection (these calculated custom fields will be always visible for any Jira project selection).
  • Add javascript_code which will calculate and store in issue.fields.customfield_NAME result of the calculation. This JavaScript code can use the issue object in the same way as in the custom JavaScript code in Jira import options.

The order of the execution of JavaScripts for custom field calculations is not defined. We recommend avoiding reference from one JavaScript calculated custom field to another as it can give an unpredictable result. 

Here is an example of a calculated custom field "Issues overdue" which will return 1 if issue has a due date and either resolution date is after a due date (for resolved issues) or a due date is in the past (for unresolved issues). Add to the advanced settings:

name = "Issues overdue"
data_type = "integer"
measure = true
javascript_code = '''
if (issue.fields.duedate) {
  var resolutionOrCurrentTimestamp = issue.fields.resolutiondate ?
    Date.parse(issue.fields.resolutiondate) : (new Date).getTime();
  if (Date.parse(issue.fields.duedate) < resolutionOrCurrentTimestamp) {
    issue.fields.customfield_overdue = 1;

Then import "Issues overdue" custom field as a measure and eazyBI will create measures "Issues overdue created", "Issues overdue due" (total of unresolved issues that are past their due date), "Issues overdue resolved" (total of resolved issues that were late).

If you would like to test and debug your JavaScript code then open Jira import options page and paste you code in Custom JavaScript code and specify an issue key on which you would like to test your JavaScript code. As it might be difficult to find your custom field value in issue.fields then during testing it is easier to assign the result to top level issue property as then you will not need to expand issue.fields. (In this example during testing assign the result to issue.customfield_overdue and when you see that it is working as expected then change it to issue.fields.customfield_overdue):

By default, you can see only standard issue fields as well as selected custom fields in the issue JSON object. Additional issue fields comment and issuelinks will be returned only if  issue.fields.comment and issue.fields.issuelinks are used in the JavaScript code to access these fields.

Custom calculated field as an interval dimension

You can define calculated custom fields also for import as an interval dimension. In this case, specify the following additional settings:

  • dimension set to true
  • In javascript_code set the value of the custom field as a number of seconds, minutes, hours or days. If the interval dimension is for a duration then this should be the number of time units between two dates. If the interval dimension is for an age then the number should be a Unix timestamp (number of seconds since January 1, 1970).
  • In time_unit specify the corresponding time unit.
  • In time_inverval specify either age or duration.
  • In intervals and interval_unit specify the default interval ranges that should be used (which can be later changed in the Analyze tab).

Here is an example of "Age since updated interval" dimension which will show the age intervals (from the last update date until now) for unresolved issues:

name = "Age since updated interval"
data_type = "integer"
dimension = true
javascript_code = '''
if (!issue.fields.resolutiondate) {
  issue.fields.customfield_updated_age_ts = Math.floor(Date.parse(issue.fields.updated) / 1000);
time_unit = "seconds"
time_interval = "age"
intervals = "/10"
interval_unit = "days"

Calculated worklog custom field

Available from eazyBI version 4.1.

If you store some structured information in worklog comments (for example if the work is billable or non-billable, or if it is overtime) then you can use calculated worklog custom fields to extract this structured information as a separate dimension.

You define a calculated worklog field as a JavaScript calculated field and in addition:

  • Specify worklog = true which will indicate that it is a worklog custom field.
  • In javascript_code use the worklog object (which contains JSON representation of one worklog entry as in issue JSON representation). Worklog comment can be accessed as worklog.comment.
    The custom field value should be assigned to worklog.customfield_NAME.

Here is an example of a Worklog Comment dimension which will import the first word in lowercase from worklog comments:

name = "Worklog Comment"
data_type = "string"
dimension = true
worklog = true
javascript_code = '''
if (worklog.comment) {
  worklog.customfield_wlcomment = worklog.comment.split(" ")[0].toLowerCase();
} else {
  worklog.customfield_wlcomment = "(no comment)"

Import Worklog Comment as a dimension and then use it to analyze Hours spent measure.

With eazyBI version 4.1. there is an option to define issue link custom fields with specified link direction. 

If you need all links with any issue link direction you could import those links with JavaScript or any scripted field in Jira. Here is an example how to import all issue links with JavaScript.

Here is an example of a All issue link dimension which will import all issue links, except epic and sub-tasks links:

name = "All links"
data_type = "string"
dimension = true
multiple_values = true
split_by = ","
javascript_code = '''
var issuelinks = new Array();
  if ( issue.fields.issuelinks ) {

  var links = issue.fields.issuelinks;
  for (var i = 0; i < links.length; i++) {
	var link = links[i];
	if (link.outwardIssue) {
		if( link.type.outward != "is Epic of" & link.type.outward != "jira_subtask_outward") {
    	if( link.type.inward != "has Epic" & link.type.inward != "jira_subtask_inward") {
  issue.fields.customfield_all_links = issuelinks.join(",");

Import All issue links as a dimension and as a property.

Last date when custom field changed

In eazyBI, it is possible to import single-value select custom field in a separate table with value changes by adding these advanced settings to your custom field (where you place your actual custom field ID instead of NNNNN)

data_type = "string"
dimension = true
separate_table = true
changes = true

Then you could import this custom field as a dimension and import also value changes in eazyBI.

After that, you could update your eazyBI advanced settings with following Javascript code that should return the last date when custom field (use your actual field name in the code instead of <Customfield name> on Line15) was changed to defined value (use your actual value in the code instead of <Value> on Line15).

Here is an example of a Jira single-value select custom field which will return the last date when a pre-defined custom field was set to the pre-defined value:

name = "Value change date"
data_type = "date"
measure = true
javascript_code = '''
var customfieldChangeDate;

if (issue.changelog && issue.changelog.histories && issue.changelog.histories.length > 0) {
  var histories = issue.changelog.histories;
  for (var i = 0; i < histories.length; i++) {
    var history = histories[i];
    if (history.items && history.items.length > 0) {
      for (var n = 0; n < history.items.length; n++) {
        var item = history.items[n];
        if (item.field == '<Customfield name>' && item.toString == '<Value>') {
          customfieldChangeDate = history.created;

issue.fields.customfield_valuechange = customfieldChangeDate;

Import Value change date as a measure and as a property.

Days for Assignee

To analyze how many days issue was assigned for each assignee until the issue resolution date, you can precalculate the time between assignee transitions based on issue change history for each issue and then import this information as a measure Days for assignee. The measure is also associated with Time dimension (by transition from assignee date)

name = "Days for assignee"
data_type = "decimal"
measure = true
multiple_dimensions = ["Time","Assignee"]
javascript_code = '''
var assigneehistory = new Array();
var datefrom = issue.fields.created;
var assignee = null;
resolution = false;

  if (historyItem.field == "assignee" && ! resolution) {
   assignee = historyItem.from;
   dateto = history.created;
     duration = (Date.parse(dateto) - Date.parse(datefrom)) / 1000 / 60 / 60 / 24;
     assigneehistory.push(dateto.toString().substr(0,10) + "," + assignee + "," + duration); 
   datefrom = dateto;
   assignee =;
 if (historyItem.field == "resolution") {
   if ( resolution = true;
   else resolution = false; 

if (issue.fields.resolutiondate && (issue.fields.assignee || assignee)) {
 if (!assignee) assignee =;
 duration = (Date.parse(issue.fields.resolutiondate) - Date.parse(datefrom)) / 1000 / 60 / 60 / 24;
 assigneehistory.push(issue.fields.resolutiondate.toString().substr(0,10) + "," + assignee + "," + duration); 

issue.fields.customfield_days_for_assignee = assigneehistory.join("\n");

Use this measure in reports together with Assignee and/or Time dimension.