It's all about the answers!

Ask a question

Defect age script


Vijayveer Reddy (17625) | asked Jan 25 '16, 7:49 a.m.
edited Jan 25 '16, 8:15 a.m. by Ralph Schoon (63.1k33645)
Hi all,

I have a dojo script which helps to display the Defect age,

Till today afternoon its worked fine, but suddenly it is displaying defect age is 3d old for a defects created after 1PM.

Request your help and suggestion..

Thank You...!

dojo.provide("example.calculated.defectAgeValueProvider");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date.stamp");

(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
var fromISOString = dojo.date.stamp.fromISOString;
  dojo.declare("example.calculated.defectAgeValueProvider", 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 ";
      }
      return " ";
    }
  });
})();

One answer



permanent link
Ralph Schoon (63.1k33645) | answered Jan 25 '16, 8:23 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Jan 25 '16, 8:24 a.m.
This has worked for me in a different context
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); // To access the work item attributes
dojo.require("dojo.date"); // We need the date class from Dojo to compare two dates
dojo.require("dojo.date.stamp"); // We need the stamp class to work with ISO date strings

.
.
.

        var beginDate = dojo.date.stamp.fromISOString(workItem.getValue("WorkItemAttributes.CREATION_DATE")); 
        // Compare the two dates returns negative value due to order
        var compare = (dojo.date.difference(Date.now(), beginDate, "day"));
        return compare + " d ";

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.