Why is this script not returning any Calculated Value
(1). Created a new Custom Field
(2). I have associated the below script with the Custom Attribute, I created above via the "Calculated Field"
(3). And yet when I make any modification to the WI, the custom field is not being populated as expected
dojo.provide("example.calculated.TotalTimeSpent");
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("example.calculated.TotalTimeSpent", null, {
getValue: function(attribute, workItem, configuration) {
var creationDate = workItem.getValue(WorkItemAttributes.CREATION_DATE);
if (creationDate) {
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 "X";
}
});
})();
5 answers
I have checked the syntax in the script, I have removed the "If Creation Date" all together,
I have modified date and Creation date as the dependent attributes and yet the Custom Attribute "TotalTimeSpent" is not getting populated.
I put the fromISOString in front of the call because the exact same script works in another RTC Instance
dojo.provide("example.calculated.TotalTimeSpent");
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("example.calculated.TotalTimeSpent", null, {
getValue: function(attribute, workItem, configuration) {
var creationDate = fromISOString(workItem.getValue(WorkItemAttributes.CREATION_DATE));
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";
}
});
})();
Comments
It might be a good strategy to start with a simple script that just returns a fixed value, if in doubt. Maybe use some techniques for debugging as described in
I tried the simplest of scripts and got the following error in the .log file
Error invoking value provider 'TotalTimeSpent' associated with the attribute 'Total Time Spent' in the project area with id '_8-_jNkaeEeWKd5cSuruh8Q'. You can link to the project area definition using a URL similar to https://thehostname:9443/jazz/process/project-areas/_8-_jNkaeEeWKd5cSuruh8Q, where the host name, port and jazz context are configured for your installation. Contact your project area administrator for assistance.
It could be due to syntax errors or other configuration problems. I suggest you remove the Caculated Value completely and start over again.
Hi I did that and have the RTC provided script with a constant being returned and still not not return any result
/***********
Licensed Materials - Property of IBM
(c) Copyright IBM Corporation 2011. All Rights Reserved.
Note to U.S. Government Users Restricted Rights:
Use, duplication or disclosure restricted by GSA ADP Schedule
Contract with IBM Corp.
***********/
dojo.provide("com.example.TotalTimeSpent");
(function() {
dojo.declare("com.example.TotalTimeSpent", null, {
getValue: function(attribute, workItem, configuration) {
return "27/05/16";
}
});
})();
Comments
Here is the message from the .log file but I am not sure what this means
!MESSAGE Error invoking value provider 'TotalTimeSpent' associated with the attribute 'Total Time Spent' in the project area with id '_8-_jNkaeEeWKd5cSuruh8Q'. You can link to the project area definition using a URL similar to https://thehostname:9443/jazz/process/project-areas/_8-_jNkaeEeWKd5cSuruh8Q, where the host name, port and jazz context are configured for your installation. Contact your project area administrator for assistance.
/*******************************************************************************
* Licensed Materials - Property of IBM
* (c) Copyright IBM Corporation 2011. All Rights Reserved.
*
* Note to U.S. Government Users Restricted Rights:
* Use, duplication or disclosure restricted by GSA ADP Schedule
* Contract with IBM Corp.
*******************************************************************************/
dojo.provide("com.example.TotalTimeSpent");
(function() {
dojo.declare("com.example.TotalTimeSpent", null, {
getValue: function(attribute, workItem, configuration) {
return "X";
}
});
})();
Comments
You don't have enough reputation to upload images. Consider contacting support. I don't see how we can make progress in the forum. Your project area process might be broken based on what I see.
Also the error message is odd. Either there is an issue with accessing the process attachment, or something else is strange. I have not seen this error message and it is not due to a syntax error or a runtime error. The script loading seems to fail already.