It's all about the answers!

Ask a question

Changing a Work Item Status based on the result of a Date Comparison

Jack C (124) | asked Sep 09 '15, 7:36 p.m.
The requirement is: Change the Work Item Status to 'Locked', when the Work Item Load Date is less than Today's Date. I have created work items were the Load Date is less than today's date but the status still won't change. In addition, is there anyway of applying this logic to all Work Items on a daily basis?

Can anyone help?

I read over the following article:

Here is my javascript:

(function() {

    dojo.declare("com.mycomp.javascript.Test_loadDateCrossed", null, {
    getValue: function(attribute, workItem, configuration) {
        try {
            var WorkItemAttributes =;
            var workItemType = (workItem.getValue(WorkItemAttributes.TYPE));
              if( workItemType == "Test" )
                  var Status = workItem.getValue(WorkItemAttributes.STATE);          
                 //Figure out the LoadDate and then clean it up
                  var loadDate = workItem.getValue(WorkItemAttributes.DUE_DATE);
                  //Remove Dashes from the Load Date
                  var loadDateNoDashes = loadDate.replace(/-/g, "");
                  //Remove the last 14 characters from Load Date leaving us with the format: YYYYMMDD
                  var loadDateNoDashesNoTime = loadDateNoDashes.slice(0,-14);
                  //Figure out the current date or Today's Date
                  var currentDate = new Date();
                                  var dd = currentDate.getDate();
                                  var mm = currentDate.getMonth+1();
                                  var yyyy = currentDate.getFullYear();
                  if(dd<10) {
                  If(mm<10) {
                    mm='0' +mm
                            currentDate = yyyy+mm+dd;
                  //Compared the Test Date against Today's Date
                  If (loadDateNoDashesNoTime < currentDate)
                      Status =; //This is the "Lock" ID.
                      return Status;
        catch(err) {
            var txt;
            txt="There was an error on this page.\n\n";
            txt+="Error description: " + err.message + "\n\n";
            txt+="Click OK to continue.\n\n";



One answer

permanent link
Donald Nong (14.4k313) | answered Sep 09 '15, 11:27 p.m.
I suggest you not do it this way as it will give you lots of trouble. There are a few things to think about.
1. When the script is executed in the RTC Eclipse client, or the server (based on Eclipse as well), the state Id is "2", not "".
2. When the script is executed in the RTC Web client (a browser), the state Id is "". This means that no matter which value you choose, it will be correct for one client and wrong for the other.
3. When using the RTC Web client, the script could be executed on the server side when the work item is being loaded. It means that you could see a "locked" state even it is not.
4. You need to do something to trigger the script, what will it be?
5. You will need a scheduled job to do periodic checks and updates, which has to be an external one as RTC does not support such feature. In this case, attribute customization will not be the choice of implementation. You may consider OLSC instead.

Your answer

Register or to post your answer.