First value of CustomField in Dimension

Hi
I am trying to create a report where I want to display in a dimension the first value of the customfield and not the current value of customfield in the issue.
Any ideas?
Regards,
Annalaura

Hi @annalaura.dinunno

one solution would be defining the import for your Jira custom field changes.

See how to import changes for single-select custom fields.
https://docs.eazybi.com/eazybijira/data-import/custom-fields/advanced-settings-for-custom-fields#Advancedsettingsforcustomfields-Importchangesofcustomfielddimensions

[jira.customfield_NNNNN]
data_type = "string"
dimension = true
changes = true
separate_table = true

You should use your single-select Jira custom field ID instead of NNNNN

After you have selected and imported changes for your custom field, you could define a new calculated field using a Javascript in advanced settings.
The Javascript should find the first value in the custom field for each issue.
And then you could import that first value in another (separate) dimension.
Try something like this (where you must use your custom field ID instead of NNNNN two places in the code and also adjust the custom dimension name for the import on line2)

[jira.customfield_fvfordim]
name = "First Value in dimension"
data_type = "string"
dimension = true
javascript_code = '''

var fval;
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.fieldid == 'customfield_NNNNN' && item.from) {
          fval = item.fromString;
        }
      }
    }
    if(fval) {
      break;
    }
  }
}
if(!fval){
issue.fields.customfield_fvfordim = issue.fields.customfield_NNNNN.value;
}
else
  issue.fields.customfield_fvfordim = fval;
'''

But this would work only for single-select Jira custom fields and the original custom field must be also selected and imported as the dimension with changes.

Martins / eazyBI support