How to display Hours for Assignee instead of Days of Assignee using JS Custom Field

Hi!
I was trying to display info about how many hours each user spent being a assignee in a issue using this script:

[jira.customfield_days_for_assignee]
name = "Days for Assignee"
data_type = "decimal"
measure = true
multiple_dimensions = ["Time","Assignee"]
javascript_code = '''
var assigneehistory = new Array();
var datefrom = issue.fields.created;
var assignee = null;
resolution = false;
	issue.changelog.histories.forEach(function(history){
	 history.items.forEach(function(historyItem){
	   if (historyItem.field == "assignee") {
	      assignee = historyItem.from;
	      if (! resolution) {
	        dateto = history.created;
	        if(assignee){
				duration = (Date.parse(dateto) - Date.parse(datefrom)) / 1000 / 3600;
				assigneehistory.push(dateto.toString().substr(0,10) + "," + assignee + "," + duration + " horas");
			}
			datefrom = dateto;
			assignee = historyItem.to;
		}
	   }
	    if (historyItem.field == "resolution") {
	      if (historyItem.to) resolution = true;
	      else resolution = false;
	    }
	 });
	});
 
	if (issue.fields.resolutiondate && (issue.fields.assignee || assignee)) {
	 if (!assignee) assignee = issue.fields.assignee.name;
		duration = (Date.parse(issue.fields.resolutiondate) - Date.parse(datefrom)) / 1000 / 3600;
		assigneehistory.push(issue.fields.resolutiondate.toString().substr(0,10) + "," + assignee + "," + duration + " horas");
	}
	issue.fields.customfield_days_for_assignee = assigneehistory.join("\n");

It only returns in days, never in hours. How can I bring this info to my report?

Hi @Abel_Oliveira,
​
The actual JavaScript code returns the figure in hours. The best practice is to rename the field to reflect its contents.
​However, you might check if you might have the old code returning days still present somewhere below in the advanced settings.
​Please check if the results are fine when you rename
“customfield_days_for_assignee”
into
“customfield_hours_for_assignee”
in the field declaration and the last line of code.
​You might as well change the field display name “Days for Assignee” into “Hours for Assignee”.
​
Regards,
​Oskars / support@eazyBI.com
​

1 Like