Attribute customization scripts / Calculated Values Scripts
I am trying to calculate the time duration between Creation date and current date. SO it means i want to calculate Task Time duration and show it on work item
My code is not mapping it on work item Presentation
dojo.provide("com.rc.TaskDuration");
dojo.require("dojo.date");
dojo.require("dojo.date.stamp");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
var fromISOString = dojo.date.stamp.fromISOString;
dojo.declare("com.rc.TaskDuration", null, {
getValue: function(attribute, workItem, configuration) {
var creationDate = fromISOString(workItem.getValue(WorkItemAttributes.CREATION_DATE));
if (creationDate) {
var ageInSeconds = (Date.now() - creationDate.getTime()) / 1000;
var days = parseInt(ageInSeconds / 86400);
var hours = parseInt((ageInSeconds-days * 86400) / 3600);
var minutes = parseInt((ageInSeconds-days * 86400 - hours * 3600) / 60);
return days + " d, " + hours + " hr, " + minutes + " min";
}
return "";
}
});
})();
As i am mapping it with a variable of type Long.
Please give me any solution.
My code is not mapping it on work item Presentation
dojo.provide("com.rc.TaskDuration");
dojo.require("dojo.date");
dojo.require("dojo.date.stamp");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
var fromISOString = dojo.date.stamp.fromISOString;
dojo.declare("com.rc.TaskDuration", null, {
getValue: function(attribute, workItem, configuration) {
var creationDate = fromISOString(workItem.getValue(WorkItemAttributes.CREATION_DATE));
if (creationDate) {
var ageInSeconds = (Date.now() - creationDate.getTime()) / 1000;
var days = parseInt(ageInSeconds / 86400);
var hours = parseInt((ageInSeconds-days * 86400) / 3600);
var minutes = parseInt((ageInSeconds-days * 86400 - hours * 3600) / 60);
return days + " d, " + hours + " hr, " + minutes + " min";
}
return "";
}
});
})();
As i am mapping it with a variable of type Long.
Please give me any solution.
Accepted answer
This is most likely a code problem. As Tiago already answered, you return a String and not a long. I would assume you use an attribute of type duration.
Try with a simple provider and check what the value of such a duration attribute is.
Try with a simple provider that returns a long all the time. If that works, go from there.
return days + " d, " + hours + " hr, " + minutes + " min";
Is a string and not a long. If you want to show that, use a string attribute.
If you want to show a duration attribute remove the characters and, if in doubt use parseInt() or some other method to return the long value.
Comments
1 vote
One other answer
You are returning a String, not a Long!
Comments
1 vote