Script Fails to run at all.
I have a Modified Date initiated script that does not give us any output to the Console. It is a calculated value. We are calling script from a Workitem Attribute that is a small-string data type, but we can't get any response from the script once it is called. Can someone please help?
// The script name must be the same in lines 1 and 8.
// This script needs to be modified to make it stop calculating when the state is set to "closed"
dojo.provide("org.example.calculated.AgeValueProvider");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date.stamp");
(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
var fromISOString = dojo.date.stamp.fromISOString;
dojo.declare("org.example.calculated.AgeValueProvider", null, {
getValue: function(attribute, workItem, configuration) {
var creationDate = fromISOString(workItem.getValue(WorkItemAttributes.CREATION_DATE));
var resolutionDate = fromISOString(workItem.getValue(WorkItemAttributes.RESOLUTION_DATE));
console.log("creation date" + creationDate);
console.log("Resolution date" + resolutionDate);
if(resolutionDate !== null){
var ageInSeconds = (resolutionDate.getTime() - creationDate.getTime()) / 1000;
var days = parseInt(ageInSeconds / 86400);
var hours = parseInt((ageInSeconds-days * 86400) / 3600);
var minutes = parseInt((ageInSeconds-days * 86400 - hours * 3600) / 60);
return days + " d, " + hours + " hr, " + minutes + " min";
}else{
var ageInSeconds = (Date.now() - creationDate.getTime()) / 1000;
var days = parseInt(ageInSeconds / 86400);
var hours = parseInt((ageInSeconds-days * 86400) / 3600);
var minutes = parseInt((ageInSeconds-days * 86400 - hours * 3600) / 60);
}
return "";
}
});
})();
// The script name must be the same in lines 1 and 8.
// This script needs to be modified to make it stop calculating when the state is set to "closed"
dojo.provide("org.example.calculated.AgeValueProvider");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date.stamp");
(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
var fromISOString = dojo.date.stamp.fromISOString;
dojo.declare("org.example.calculated.AgeValueProvider", null, {
getValue: function(attribute, workItem, configuration) {
var creationDate = fromISOString(workItem.getValue(WorkItemAttributes.CREATION_DATE));
var resolutionDate = fromISOString(workItem.getValue(WorkItemAttributes.RESOLUTION_DATE));
console.log("creation date" + creationDate);
console.log("Resolution date" + resolutionDate);
if(resolutionDate !== null){
var ageInSeconds = (resolutionDate.getTime() - creationDate.getTime()) / 1000;
var days = parseInt(ageInSeconds / 86400);
var hours = parseInt((ageInSeconds-days * 86400) / 3600);
var minutes = parseInt((ageInSeconds-days * 86400 - hours * 3600) / 60);
return days + " d, " + hours + " hr, " + minutes + " min";
}else{
var ageInSeconds = (Date.now() - creationDate.getTime()) / 1000;
var days = parseInt(ageInSeconds / 86400);
var hours = parseInt((ageInSeconds-days * 86400) / 3600);
var minutes = parseInt((ageInSeconds-days * 86400 - hours * 3600) / 60);
return days + " d, " + hours + " hr, " + minutes + " min";
}
return "";
}
});
})();
Accepted answer
2 other answers
It may be a silly mistake - you said the script is "Modified Date initiated", but the script reads Resolution Date. Make sure that you make the dependency right.
Another thing to note - you should also check the null value for variable "creationDate", as it will be definitely null during the creation of a new work item.
Another thing to note - you should also check the null value for variable "creationDate", as it will be definitely null during the creation of a new work item.
Actually the correct answer was how to get any of the scripts to run for a workitem and a project. What solved it was we found a script entry /workitem/scripts/common/sar_warranty.js that had zero bytes. We found that condition causes no scripts to run for the entire project. We deleted this zero byte script file and everything began to work again. That smells like a bug to me.
Comments
I did see such behavior before, and it is quite easy to spot using a debugger. The JavaScript engine appears to evaluate all the scripts as a whole, and a single corrupted script can render all scripts invalid. Regarding your original issue, you described it in a way that made us believe only the one quoted script didn't work. How can you expect a "correct" answer for such a question then?
Comments
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Apr 01 '16, 12:53 a.m.You should be able to use a debugger or look at the logs to get an idea. See Process Enactment Workshop for the Rational solution for Collaborative Lifecycle Management Lab 5