Why is this script not returning any Calculated Value
I have
(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";
}
});
})();
(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
Hi Ralph,
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";
}
});
})();
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
Comments
Yes Java Scripting is enabled. Here is the error from the log and the script
/*******************************************************************************
* 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";
}
});
})();
/*******************************************************************************
* 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";
}
});
})();