How long Issue was flagged to Paused (Cumulative)

Hello

We receive a customer need . He need to know how How long (Days and Hours) Issue was flagged to Paused (Cumulative).

Example:
On Monday , ticket was flagged to Paused
On Tuesday , Paused removed
Duration=2 days
On Friday, ticket was flagged to Paused another time
Duration = 3days
On sunday , Paused was removed
The final value of duration is: 5 days

I used this script but i dont know how to calculate cumulative :smile:

[jira.customfield_days_flagged]
name = "Days Flagged Paused"
data_type="decimal"
measure = true
javascript_code='''

var date_from = Date.parse(issue.fields.created);
var days_flagged = 0.0;
issue.changelog.histories.forEach(function(history){
    history.items.forEach(function(historyItem){
      if (historyItem.field == "Flagged") {
        to = historyItem.toString;
        from = historyItem.fromString;
        if(to.equals("Paused")) {
          date_from = Date.parse(history.created);
        }
        if (from && from.equals("Paused")) {
          date_to = Date.parse(history.created);
          days_flagged += (date_to - date_from) / 1000/ 60 /60 / 24 ;
        }
      }
    });
  });
if (days_flagged>0) issue.fields.customfield_days_flagged=days_flagged;
'''

Thanks for helping,
Nour

Any newssssss ???

Hi,

We can adjust the Javascript calculated custom field to allow the cumulative calculation of this measure over time. Currently, the code accumulates all the flagged periods in a single total, but it is possible to record each period separately in the measure.

The settings of this measure are the following:

[jira.customfield_days_flagged_c]
name = "Days Flagged Cumulative"
multiple_dates=true
data_type="decimal"
measure = true
javascript_code='''
var date_from = Date.parse(issue.fields.created);
var days_flagged = 0.0;
var result = new Array();
issue.changelog.histories.forEach(function(history){
    history.items.forEach(function(historyItem){
      if (historyItem.field == "Paused") {
        to = historyItem.toString;
        from = historyItem.fromString;
        if(to.equals("Impediment")) {
          date_from = Date.parse(history.created);
        }
        if (from && from.equals("Paused")) {
          date_to = Date.parse(history.created);
          days_flagged = (date_to - date_from) / 1000/ 60 /60 / 24 ;
          result.push(history.created.substr(0,10)+","+days_flagged);
        }
      }
    });
  });
if (days_flagged>0) issue.fields.customfield_days_flagged_c=result.join("\n");
'''

This measure gives the same value in total but can be distributed by dates if an issue was flagged several times:

Kindly,
Janis, eazyBI support

It works thanks :grinning:
But i have a problem : some tickets are flagged to Paused during creating the issue.
So the script doesn’t include those tickets, I think because we use history table
How can i correct that ?