[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.
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.
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
everything from your script looks good except for the extra "}" just after the if statement.
below is the code which worked for me
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;
}
});
})();
Comments
One other answer
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;
}
});
})();
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;
}
});
})();