It's all about the answers!

Ask a question

work item attribute customization: disable time spent on past DUE DATE


Milan Krivic (9807160132) | asked May 28 '13, 4:22 a.m.
 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



permanent link
Elisabeth Carbone (61698) | answered May 28 '13, 4:44 a.m.
JAZZ DEVELOPER
Milan,
have you tried to add
console.log(.....); to see the actual values and kind of debug your script?

/Elisabeth

Comments
Milan Krivic commented May 28 '13, 4:53 a.m.

 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...


permanent link
Eric Jodet (6.3k5106120) | answered May 28 '13, 5:55 a.m.
JAZZ DEVELOPER
 Hello,
you may want to compare your code with the one available here - https://jazz.net/library/article/1003/#calc-values

Hope it helps.
Eric.

permanent link
Milan Krivic (9807160132) | answered May 28 '13, 7:17 a.m.
 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... :(

permanent link
Eric Jodet (6.3k5106120) | answered May 28 '13, 8:26 a.m.
JAZZ DEVELOPER
 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.


Comments
Milan Krivic commented May 28 '13, 8:52 a.m.

Hi Eric, 


it works now :)

I forgot to write the following line:

var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;

I found it in log file that I am missing it.

Thanks for the help, to you and  Elisabeth.

Regards,


Eric Jodet commented May 28 '13, 9:00 a.m.
JAZZ DEVELOPER

 glad it works now.

Thanks


permanent link
almsupport alm (133) | answered Oct 22 '19, 8:25 a.m.

 Hi,


I tried the above code which works for you but its not working for me.



Comments
Ralph Schoon commented Oct 22 '19, 8:57 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Consider creating a question including your code and what you are trying to do. 


permanent link
almsupport alm (133) | answered Oct 23 '19, 12:24 a.m.

 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.


Comments
almsupport alm commented Oct 23 '19, 12:39 a.m.

Hi,


Please suggest how to configure the cod to project/work item. 

Your answer


Register or to post your answer.