Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

My delay script is not working

 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

0 votes


Accepted answer

Permanent link
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

0 votes


One other answer

Permanent link
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";
}
});
})();

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details

Question asked: Feb 21 '15, 6:00 a.m.

Question was seen: 3,399 times

Last updated: Feb 26 '15, 5:34 a.m.

Confirmation Cancel Confirm