work item attribute customization: disable time spent on past DUE DATE
Hi,
I need some help here.
I created the following condition script for setting read-only TIME SPENT attribute when DUE DATE is past:
dojo.provide("com.apisit.disable.timeEnter");
dojo.require("dojo.date");
dojo.require("dojo.date.stamp");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
dojo.declare("com.apisit.disable.timeEnter", null, {
matches: function(workItem, configuration) {
var currentDate= new Date();
var day = currentDate.getDate();
var month = currentDate.getMonth() + 1;
var year = currentDate.getFullYear();
getAttributeData("Due Date: ", WorkItemAttributes.DUE_DATE);
var date_enter = dojo.date.stamp.fromISOString(workItem.getValue(WorkItemAttributes.DUE_DATE));
var day_enter = date_enter.getDate();
if(day > day_enter){
return true;
}
else
{
return false;
}
}
});
})();
Then, in Operation Behavior I choose Read-Only Attributes For Condition for adding this script, where I choose Time Spent attribute,
but it doesn't work.
Where I mistake..?
Regards,
6 answers
Milan,
have you tried to add
console.log(.....); to see the actual values and kind of debug your script?
/Elisabeth
have you tried to add
console.log(.....); to see the actual values and kind of debug your script?
/Elisabeth
Comments
HI Elisabeth,
Yes, I made also another script for console logs to show outputs on Description work item attribute, and when I choose past date in DUE DATE, I can see the changes in Description. For example, if I choose 18. May of 2013, as past date I get 18, and for current date I get 25.
I also put one if to match the values which is bigger, just to ensure that I got real values for dates, and It works.
But I am wondering why this doesn't work for time spent...
Hello,
you may want to compare your code with the one available here - https://jazz.net/library/article/1003/#calc-values
More examples here https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Script_Based_Validation
Hope it helps.
Eric.
Hi Eric,
I tried this:
dojo.provide("com.apisit.disable.timeEntering");
dojo.require("dojo.date");
dojo.require("dojo.date.stamp");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
dojo.declare("com.apisit.disable.timeEntering", null, {
matches: function(workItem, configuration) {
var currentDate= new Date();
var due_date = dojo.date.stamp.fromISOString(workItem.getValue(WorkItemAttributes.DUE_DATE));
if(dojo.date.compare(due_date,currentDate) < 0){ //if due_date is earlier than today date
return true;
}
else
{
return false;
}
}
});
})();
but this doesn't work also... :(
Hello Milan,
date compare is performed using: dojo.date.compare
so your code should be OK
As Elisabeth underlined, you may want to console.log(due_date);
and ensure it's not null or check the format.
Hope it helps
Eric.
HI,
I tried the below code
dojo.provide("com.apisit.disable.timeEntering");
dojo.require("dojo.date");
dojo.require("dojo.date.stamp");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("com.apisit.disable.timeEntering", null, {
matches: function(workItem, configuration) {
var currentDate= new Date();
var due_date = dojo.date.stamp.fromISOString(workItem.getValue(WorkItemAttributes.DUE_DATE));
if(dojo.date.compare(due_date,currentDate) < 0){ //if due_date is earlier than today date
return true;
}
else
{
return false;
}
}
});
})();
Please review and suggest.