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:


(function() {
var WorkItemAttributes =;
var fromISOString =;
  dojo.declare("example.calculated.TotalDelay", null, {

    getValue: function(attribute, workItem, configuration) {
      var BaselineEndDate = fromISOString(workItem.getValue(project.baselineduedate));
      if (BaselineEndDate) {
        var DelayInSeconds = ( - 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.

Accepted answer

permanent link
Ralph Schoon (63.3k33646) | answered Feb 23 '15, 3:19 a.m.
You can not simply use + and - to operate on dates. You can not simply return a data. See 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(""); // To access the work item attributes
dojo.require(""); // We need the date class from Dojo to compare two dates
dojo.require(""); // 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 ="")); 
        // Get the current attribute's value and make a Date object from it
        console.log("I got: ["+workItem.getValue(attributeId)+"]");
        var endDate=;        
        // Compare the two dates returns negative value due to order
        var compare = -(, 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.



(function() {
var 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='project.baselineduedate'));
        var currentDate= new Date();
        var dayDiff=, 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.