First transition to Transition Status (javascript field)

Hi folks!

We had the need to develop a report that shows how many issues were transitioned to statuses in time. But it should only consider the first time that the issues were transitioned to that statuses.

The solution provided by Zane in here Issues by Transition to status first date - distinct count worked. But with time we started having timeout due to the amount of issues imported.

So we created a javascript field to make it work again.
This is the configuration to add in Advanced Settings:
[jira.customfield_firstTransition]
name = “First transition”
data_type = “integer”
measure = true
multiple_dimensions = [“Transition Status”, “Time”]
split_by = “,”
javascript_code = ‘’’
var firstTransition = new Array();
issue.changelog.histories.forEach(function(history){
history.items.forEach(function(historyItem){
if (historyItem.field == “status”) {
to = historyItem.toString;
date_to = history.created;
if (firstTransition.filter(str => str.startsWith(to + “,”)).length == 0) {
firstTransition.push(to + “,” + date_to + “,1”);
}
}
});
});
issue.fields.customfield_firstTransition = firstTransition.join(“\n”);
‘’’

This will create a new custom field named “First transition” to be imported as measure or properties. You should import it as “measure”.

After the import is done, use the measure “First transition”.

1 Like

The code looks better this way:

[jira.customfield_firstTransition]
name = "First transition"
data_type = "integer"
measure = true
multiple_dimensions = ["Transition Status", "Time"]
split_by = ","
javascript_code = '''
var firstTransition = new Array();
issue.changelog.histories.forEach(function(history){
    history.items.forEach(function(historyItem){
      if (historyItem.field == "status") {
        to = historyItem.toString;
        date_to = history.created;
        if (firstTransition.filter(str => str.startsWith(to + ",")).length == 0) {
          firstTransition.push(to + "," + date_to + ",1");
        }
      }
   });
});
issue.fields.customfield_firstTransition = firstTransition.join("\n");
'''