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

1 Like

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 ?

FYI, I believe the above Javascript calculations via the issue History (both of them) will not take into account time for issues that are currently flagged i.e. the time since the issue was last flagged and now(). Since it is using Functional (“parallel”) programming I am not sure how to suggest an easy fix. Perhaps keep track of the largest/latest date that has a ‘to’ of ‘Paused’ and then at the end check to if the issue ‘flagged’ and if so subtract that from the now() timestamp. UPDATE: here is my solution using what I said in the previous sentence - note that I hard-coded the number for the ‘custom field’ in my instance for the Flagged field:
var date_from = Date.parse(issue.fields.created);
var days_flagged = 0.0;
var latest_date = date_from;
issue.changelog.histories.forEach(function(history){
history.items.forEach(function(historyItem){
if (historyItem.field == “Flagged”) {
to = historyItem.toString;
from = historyItem.fromString;
if(to.equals(“Impediment”)) {
date_from = Date.parse(history.created);
if (date_from > latest_date) {
latest_date = date_from;
}
}
if (from && from.equals(“Impediment”)) {
date_to = Date.parse(history.created);
days_flagged += (date_to - date_from) / 1000/ 60 /60 / 24 ;
}
}
});
});
if (issue.fields.customfield_10023) {
days_flagged += (new Date() - latest_date) / 1000/ 60 /60 / 24;
}
if (days_flagged>0) issue.fields.customfield_days_flagged=days_flagged;

Hi,

This Javascript is designed to track the days in Flagged status for the “completed cycles”. That means the days will be counted once the Flag is removed.

The calculation of the time for currently flagged issues will not be precise with the Javascript since the Javascript is executed during the data import. A solution to count the time in the currently flagged status could be calculated using the custom measure in the report.

For each issue, the following formula gives the date and time when the last transitions in the Flagged field happened:

TimestampToDate(
([Measures].[Transition to last timestamp],
[Transition Field].[Flagged])  

)

If you know the issue is currently flagged, the following formula gives the days:

DateDiffDays(
  TimestampToDate(
    ([Measures].[Transition to last timestamp],
     [Transition Field].[Flagged])  
  ),Now()
)

Kindly,
Janis, eazyBI support