# First transition to Transition Status (javascript field)

**URL:** <https://community.eazybi.com/t/first-transition-to-transition-status-javascript-field/17537>\
**Category:** Tips & Tricks\
**Tags:** time-dimension, javascript, status, jira\
**Created:** [June 21, 2024, 2:08pm UTC](https://community.eazybi.com/t/first-transition-to-transition-status-javascript-field/17537 "2024-06-21T14:08:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kondo](https://community.eazybi.com/letter_avatar_proxy/v4/letter/k/e47774/32.png) [@Kondo](https://community.eazybi.com/u/Kondo)\
**Post date:** [June 21, 2024, 2:08pm UTC](https://community.eazybi.com/t/first-transition-to-transition-status-javascript-field/17537/1 "2024-06-21T14:08:49Z")

</div>

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](https://community.eazybi.com/t/issues-by-transition-to-status-first-date-distinct-count/14590) 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”.

---

<div class="post-metadata">

**Author:** ![Kondo](https://community.eazybi.com/letter_avatar_proxy/v4/letter/k/e47774/32.png) [@Kondo](https://community.eazybi.com/u/Kondo)\
**Post date:** [June 21, 2024, 2:09pm UTC](https://community.eazybi.com/t/first-transition-to-transition-status-javascript-field/17537/2 "2024-06-21T14:09:30Z")

</div>

The code looks better this way:

```auto
[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");
'''

```
