It's all about the answers!

Ask a question

My delay script is not working


Georges Oneissy (53522) | asked Feb 21 '15, 6:00 a.m.
edited Feb 21 '15, 6:01 a.m.
 Here's my script:

dojo.provide("example.calculated.TotalDelay");
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.TotalDelay", null, {

    getValue: function(attribute, workItem, configuration) {
      var BaselineEndDate = fromISOString(workItem.getValue(project.baselineduedate));
      if (BaselineEndDate) {
        var DelayInSeconds = (Date.now() - BaselineEndDate.getTime()) / 1000;
        var days           = parseInt(DelayInSeconds / 86400);
        return days + " d ";
      }
      return "";
    }
  });
})();

I have a custom attribute Baseline End Date (ID: project.baselineduedate | Type: Timestamp) and I want to calculate the difference between the current date and the Baseline End Date and show it.
I created the custom attribute "Project Delay" of type Decimal, calculated value: Project Delay, dependencies Baseline End Date and Read-Only presentation. I still don't find my error. 
Any help is hugely appreciated.
Georges

Accepted answer


permanent link
Ralph Schoon (63.6k33646) | answered Feb 23 '15, 3:19 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
You can not simply use + and - to operate on dates. You can not simply return a data. See https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript and look at the Timestamp section. Search the internet for how to operate on dates with JavaScript

Here is example code for calculating:

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 message= "Date must be at least 30 days from now"; 
       
       // Work Item new: not initialized - provides todays date. Once created provides the creation date 
        var beginDate = dojo.date.stamp.fromISOString(workItem.getValue("com.ibm.team.workitem.attribute.creationdate")); 
        // Get the current attribute's value and make a Date object from it
        console.log("I got: ["+workItem.getValue(attributeId)+"]");
        var endDate= dojo.date.stamp.fromISOString(workItem.getValue(attributeId));        
        // Compare the two dates returns negative value due to order
        var compare = -(dojo.date.difference(endDate, beginDate, "day"));
        if (compare>= 30) { // make sure endDate is not earlier than beginDate + 30

Ralph Schoon selected this answer as the correct answer

One other answer



permanent link
Georges Oneissy (53522) | answered Feb 26 '15, 5:33 a.m.
edited Feb 26 '15, 5:34 a.m.
Solved 

dojo.provide("org.example.workitems.providers.delaysindays");

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

(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;

dojo.declare("org.example.workitems.providers.delaysindays", null, {

    getValue: function(attributeId, workItem, configuration) {

        // Get the creation date and the current date and compute the difference in days.
        var baselineDueDate= dojo.date.stamp.fromISOString(workItem.getValue('project.baselineduedate'));
        var currentDate= new Date();
        var dayDiff= -dojo.date.difference(currentDate, baselineDueDate, "day");
        return dayDiff + " days";
}
});
})();

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.