Requirement : If the Loadset(a work-item) Date is less than Today’s Date, change the status to "LockForLoad" automatically
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
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
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
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.