Sum DateDiffWorkhours on a specific status

Hi Thomas,

​Importing multiple timestamps as comma-separated values into a property, unfortunately, might not solve your request.
​Although they might be available, the MDX does not have the proper construction to cycle through the timestamps and calculate the interval length.

​The solution might be to create a JavaScript calculated custom field that finds the time spent in specific status and processes that to retrieve working hours only.

​You might find the common JavaScript code for the workhours function here - Assignment hrs work days eazybi.

​After adding the code for the workhours function, the code to retrieve workhours spent in a specific status and register time against the date of exiting status might be as follows.

[jira.customfield_statWorkHours]
name="Workhours in status"
data_type="decimal"
measure=true
multiple_dimensions=["Time"]
javascript_code='''

var isWorked = false;
var forRecord = false;
var duration = 0;
var currStartDate = null;
var oldStartDate = null;
var result = new Array();

var workStatuses = ["In Progress"]

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.field == "status") {
                    if (workStatuses.indexOf(item.toString) > -1) {
                        isWorked = true;
                        forRecord = false;
                    } else if (workStatuses.indexOf(item.toString) == -1) {
                        isWorked = false;
                        forRecord = true;
                    }
                  if (isWorked && !forRecord) {
                     currStartDate = history.created;}
                  else if (!isWorked && forRecord) {
                    oldStartDate = currStartDate;
                    currStartDate = history.created;
                    duration =  workinghours ( oldStartDate , currStartDate );
                    if (duration >0){
                    result.push( currStartDate.substr(0,10)+", "+ duration);}
                    forRecord = false;
                   }
               }
            }
        }
    }
   if(result){
    issue.fields.customfield_statWorkHours = result.join("\n");
   } 
}
'''


Regards,
​Oskars / support@eazyBI.com

1 Like