Defect Age by State
![]()
hello,
I have placed a standard script for the defect age calculation, typically calculates the dafect age from creation date to closed date. But we would like to calculate the age by each state. Example defect OPEN and assigned to developer and when moves to FIXED state , we would like to capture the time spent till time stamp of FIXED from creation. so is there any solution already implemented with such scenario. Thank You....! |
Accepted answer
![]()
Hello Donald,
I was able to fix the issue now. Please find the working code below. In the above code missed to provide string formatted input to date.dojo.diff() function Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot find function difference in object [object Object]. (defectage_fix2.js#18). Here is the working code for Defect Age. We can use "weekday" for only weekday calculations and "day" for week calculation. ------------------------------------------------------------------------------------------------------------------------------------------- dojo.provide("com.example.common.GetTurnAroundTime"); dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); dojo.require("dojo.date"); dojo.require("dojo.date.stamp"); (function() { var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes; dojo.declare("com.example.common.GetTurnAroundTime", null, { getValue: function(attributeId, workItem, configuration) { var resoTime= 0; var endDateTimestamp = Date.now(); var iniDateTimestamp = workItem.getValue(WorkItemAttributes.CREATION_DATE); if ((endDateTimestamp != null) && (iniDateTimestamp != null)) { var iniDate= dojo.date.stamp.fromISOString(iniDateTimestamp); var resoDate = dojo.date.stamp.fromISOString(endDateTimestamp); var resoTime= dojo.date.difference(iniDate, resoDate, "weekday"); } console.log("GetTurnAroundTime End - resoTime:" + resoTime); return resoTime; } }); })(); Ralph Schoon selected this answer as the correct answer
|
5 other answers
![]()
Hello,
This is a perfect code for defect age calculation based on date change for weekdays. Even we can exclude and include weekend with this dojo.data.difference functionality like below. dojo.date.difference(iniDate, resoDate, "weekday"); - Working days only calculation dojo.date.difference(iniDate, resoDate, "day"); - Entire Week calculation ****************************************************************************************************************** Java Script to associate to work items for defect age calculation for working days ****************************************************************************************************************** dojo.provide("com.example.common.GetTurnAroundTime"); dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); dojo.require("dojo.date"); dojo.require("dojo.date.stamp"); (function() { var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes; dojo.declare("com.example.common.GetTurnAroundTime", null, { getValue: function(attributeId, workItem, configuration) { var resoTime= 0; var endDateTimestamp = Date.now(); var iniDateTimestamp = workItem.getValue(WorkItemAttributes.CREATION_DATE); if ((endDateTimestamp != null) && (iniDateTimestamp != null)) { var iniDate= dojo.date.stamp.fromISOString(iniDateTimestamp); var resoDate = dojo.date.stamp.fromISOString(endDateTimestamp); var resoTime= dojo.date.difference(iniDate, resoDate, "weekday"); } console.log("GetTurnAroundTime End - resoTime:" + resoTime); return resoTime; } }); })(); |
![]()
Since it is specific to states unique to your environment, I doubt that any out-of-box implementation exists. You will need to get the history of the state changes and calculate the length of each period.
Comments Here is a good blog that you can use as a reference. Hi Donald,
You need to learn how to debug the scripts. There are a few things to consider.
// Get the creation date and the current date and compute the difference in days. var creationDate= dojo.date.stamp.fromISOString(workItem.getValue(WorkItemAttributes.CREATION_DATE)); var currentDate= new Date(); var dayDiff= dojo.date.difference(currentDate, creationDate, "day");https://jazz.net/wiki/bin/view/Main/AttributeCustomization 4. The real issue - the "creationDate" attribute cannot be retrieved using the above script, so the variable "creationDate" is null.The "dueDate" attribute also has the same problem, while "modified" works just fine. I have not figured out what's going on yet. Hi Donald,
You put the two dates in the difference() function the wrong way round, so you most likely get a negative value. It's always a good idea to read the API reference when developing codes.
var dayDiff = dojo.date.difference(creationDate);Also make sure that the script does get "triggered". For example, set the dependency on an attribute that will more likely get changed first. |