It's all about the answers!

Ask a question

Requirement : If the Loadset(a work-item) Date is less than Today’s Date, change the status to "LockForLoad" automatically


Shuchi Arora (1112) | asked Sep 11 '15, 1:39 a.m.
edited Sep 11 '15, 3:03 a.m. by Ralph Schoon (63.1k33645)

Hello,

If someone could help me with the correct approach to enable this functionality in RTC, it would be really great.

The requirement is to automatically change the status of the loadset - workItem as soon as the Loadset Date(Due-Date for the load) becomes less than today's date.

I have written a script in "Calculated Value" area of "Attribute Customization", linked it with the "Status" Attribute, assigned "Due Date" as its dependency too.

Initially I got compilation errors too which ensured the script gets hit, but now it looks like the script is not working for what it was written, not sure if I am missing on a Configuration or I need to write the script some where else, or I need to write a perl/shell script for the same..like we have cron jobs in Unix.

Please advice a correct approach.

The script I have written is:

dojo.provide("com.tvlprt.javascript.loadset_loadDateCrossed");

dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

dojo.require("dojo.date");

dojo.require("dojo.date.stamp");

 

(function() {

    dojo.declare("com.tvlprt.javascript.loadset_loadDateCrossed", null, {

 

    getValue: function(attribute, workItem, configuration) {

 

        try {

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

                  var workItemType = (workItem.getValue(WorkItemAttributes.TYPE));

                 

                          

                    if( workItemType == "loadset" )

                  {

                          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) {

                              dd='0'+dd

                              }

                 

                          If(mm<10) {

                              mm='0' +mm

                              }

                         

                  currentDate = yyyy+mm+dd;

                         

                          

                  //Compared the Loadset Date against Today's Date

                  If (loadDateNoDashesNoTime < currentDate)

                  {

                      Status = com.ibm.team.workitem.loadSetWorkflow.state.s2; //This is the "LockforLoad" 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";

            alert(txt);

}

}

});

})();

2 answers



permanent link
Ralph Schoon (63.1k33645) | answered Sep 11 '15, 3:13 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
When do attribute customization scripts run? They run if the work item is opened in an editor and if the dependent attribute changes.

Attribute customization is not a valid approach in this situation. You would have to create automation that
  • is scheduled
  • queries the work items for overdue
  • manipulates the work item state
This can be a server extension, or easier to develop initially, a plain java client library api tool that is scheduled in a cron job or (easier) in a scheduled build.

See https://rsjazz.wordpress.com/2012/10/29/using-work-item-queris-for-automation/ or https://rsjazz.wordpress.com/2012/11/19/using-expressions-for-automation/  . The blog has also code to change states of work items. If you have no experience with Java based RTC API coding, start here: https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/ and follow the links in the post how to set up your environment. 

Comments
Ralph Schoon commented Sep 11 '15, 3:28 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I should add, that a lot of the requests for automation of state changes for work items, especially if they are not related to changing states in other work items are mostly driven by some process requirement.

In many of these cases the requirement is questionable and there would likely be a better approach to this. Thus a lot of extensions are written because the teams can't agree on a reasonable process. This often complicates the tool usage, increases the process complexity and increases the expense for running the tools as they need to be created and maintained.

It is worthwhile to consider if out of the box means like dashboards that show the items in question would be more appropriate.


permanent link
Donald Nong (14.5k414) | answered Sep 11 '15, 5:29 a.m.
It looks to be the same question in this post.
https://jazz.net/forum/questions/206399/changing-a-work-item-status-based-on-the-result-of-a-date-comparison
My advise? Don't do it.

Comments
Jack C commented Sep 11 '15, 9:59 a.m. | edited Sep 13 '15, 9:45 p.m.

Per Donald's response: Why are you recommending this NOT be done. Can you provide more of an explanation? Thanks.


Donald Nong commented Sep 13 '15, 9:58 p.m.

Have you checked my response in the other post? The approach will cause lots of confusion and will do more harm than good.
1. As I said in the other post, if a work item satisfies the conditions for the "LockForLoad" status, it will be displayed in such status in the web client regardless its actual state. For example, a work item with "New" state will be displayed as "LockForLoad". Do you want this to happen?
2. If you change the state of a work item, and the work item satisfies the condition for the "LockForLoad" status, the resulted state will be "LockForLoad", not the one you intend to change to. Do you want this to happen?
You may be able to avoid #2 with some checking in the script but #1 seems impossible to avoid.


Jack C commented Sep 14 '15, 5:53 p.m. | edited Sep 14 '15, 7:57 p.m.

Your comments and responses are still unclear to me.

To answer your questions:

1) Yes, I want the status to change to 'LockforLoad' once the date condition is met, even if the status is 'New'.

2) I do not understand Question #2. Are you saying that once a work time is in the LockForLoad status (base on the date condition being met), it will always be in the LockforLoad status because of the chron job that runs.


Donald Nong commented Sep 14 '15, 8:09 p.m.

Let me put it in another way.
1. If a work item with state "New" meets the date condition, when you view this work item in the Eclipse client, you will see the state "New". But in the Web client, you will see "LockForLoad". There is no "change" action, because you just "view" it. Sounds confusing? Yes, that's what I want to say - this approach will introduce confusion.
2. When a user tries to change the state, the script can override the result without the user knowing. There is no "cron" job involved because you cannot schedule such thing with attribute customization.
You can do it the easy way and see for yourself - in the script, remove all the logic and let it simply always return "LockFoLoad". Verify the script in both Eclipse client and Web client. If you can make it work in both clients, do let me know how you achieve it (this is yet another "confusion" that you will face).

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.