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

[closed] how to show the difference between current date and due date through script based calculated value?

I am using RTC3013 and want to show the difference between current date and due date in the task.
I followed the instruction in the below article to set the ccm/admin first.
Then create script as below

dojo.provide("ibm.example.workitems.providers.CalculatedValueSkeleton");
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("ibm.example.workitems.providers.CalculatedValueSkeleton", null, {

    getValue: function(attributeId, workItem, configuration) {


    var dueDate= dojo.date.stamp.fromISOString(workItem.getValue(WorkItemAttributes.DUE_DATE));
        var currentDate= new Date();
        var dayDiff= dojo.date.difference(dueDate,currentDate, "day");
        var result = 0;
    if (dayDiff > 0) result=dayDiff;         
    }
        return result;
    }
});
})();

In Eclipse client, add new calculated value to customized attribute and point to the above js file
Create a new attribute and use the new created calculated value and set it as dependent on duedate.
Add the new attribute to task presentation.
When I create a new task, I can see the new attribute is there, but after I select a due date and save the WI, nothing happens to the attribute(blank)

I am wondering how I can achieve that: whether something is wrong in my script or I missed anything?
Would appreciate if anyone can comment on what's wrong. Thank you very much.

1

0 votes


The question has been closed for the following reason: "The question is answered, right answer was accepted" by rschoon Jun 30 '15, 3:24 a.m.

Accepted answer

Permanent link
everything from your script looks good except for the extra "}" just after the if statement.

below is the code which worked for me
dojo.declare("org.scripts.datediff", null, {

    getValue: function(attributeId, workItem, configuration) {

           var dueDate = dojo.date.stamp.fromISOString(workItem.getValue(WorkItemAttributes.DUE_DATE));
        var currDate = new Date();
               
        var day = dojo.date.difference(currDate, dueDate, "day");
       
        return day;
    }
});
})();
Ralph Schoon selected this answer as the correct answer

1 vote

Comments

Thanks Dinesh for pointing out the problem. I tried to remove } and it does work for me now.

Hi, I tried the sample code above, I have made the field read-only, But even after the script automatically populates the field, it keeps the save button always enabled. Could you help to to fix this ?

The code has a problem and it is not working, because it does not convert the date back to something RTC can understand. You have to use fromISOString to get the date format and you have to use toISOString for the format to be converted to return it. See https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript


One other answer

Permanent link
Hi,

We were working on the defect age and got this code to calculate the age diff . And i wrote the code as below with reference to above code to calculate the diff of creation date and date now. And i have created an attribute of small sting and added dependency as creation date ,attached the script.But the code is not working for me.

Could you please review and guide me where it went wrong.


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

    getValue: function(attribute, workItem, configuration) {

      var creationDate = dojo.date.stamp.fromISOString(workItem.getValue(WorkItemAttributes.CREATION_DATE));

console.log("status enter");
console.log(creationDate);

var currentDate = new Date();
    var dayDiff= dojo.date.difference(creationDate,currentDate, "day");
        var result = 0;
    if (dayDiff > 0) result=dayDiff;        
   
        return result;
    }
  });
})();


0 votes

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
× 369
× 42

Question asked: Jul 27 '12, 5:03 a.m.

Question was seen: 8,620 times

Last updated: Jul 12 '15, 6:20 a.m.

Confirmation Cancel Confirm