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
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.
Ashwath G
commented Jul 03 '15, 3:21 a.m.
Hi Donald,
Donald Nong
commented Jul 03 '15, 6:25 a.m.
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. |
Not possible out of the box.
You need java script. creating java script is simple & easy. Comments Hello Donald, Chidambaram,
Ashwath G
commented May 13 '15, 11:32 a.m.
Hello Donald, Chidambaram,
|
Hello Donald,
I have tried with your reference code and API suggested. And for defect age attribute i have created dependency on creation date.Could you please check this code once .... dojo.provide("example.calculated.defectAgeValueProviderfix3"); 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.defectAgeValueProviderfix3", null, { getValue: function(attribute, workItem, configuration) { var creationDate = dojo.date.stamp.fromISOString(workItem.getValue(WorkItemAttributes.CREATION_DATE)); var currentDate = new Date(); //var dayDiff = dojo.date.difference(currentDate, creationDate, "day"); var dayDiff = dojo.date.difference(creationDate); var result = 0; console.log("--status enter after diff---"); if (dayDiff > 0) result=dayDiff; return result; } }); })(); Comments
Donald Nong
commented Jul 06 '15, 8:09 p.m.
The code looks OK but the dependency sounds strange. Why don't you use the "state" as the dependency? The "creation date" will change once only - that's when the work item is created, and you will always get 0 for dayDiff in this case.
Hello Donald,
|
Hello Donald,
I have changed the dependency of the attribute from creation date to state and also checked with modified date too. And found below errors in the eclipse log. What could be the cause and how to fix this. !ENTRY com.ibm.team.rtc.common.scriptengine 1 0 2015-07-08 18:39:39.809 !MESSAGE LOG: '-------status entered into script------' !ENTRY com.ibm.team.rtc.common.scriptengine 1 0 2015-07-08 18:39:39.809 !MESSAGE LOG: {} !ENTRY com.ibm.team.workitem.common 4 0 2015-07-08 18:39:39.819 !MESSAGE Error invoking value provider 'com.ibm.team.workitem.valueproviders.VALUE_PROVIDER._Y2UX4CVMEeWqVPl8dLspjA' !STACK 0 com.ibm.team.repository.common.TeamRepositoryException: Unexpected exception type at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider.handleException(ScriptAttributeValueProvider.java:281) at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider.getValue(ScriptAttributeValueProvider.java:69) at com.ibm.team.workitem.common.internal.attributeValueProviders.AttributeValueProviderRegistry$SafeValueProvider.getValue(AttributeValueProviderRegistry.java:42) at com.ibm.team.workitem.common.internal.model.impl.AttributeImpl.getValue(AttributeImpl.java:899) at sun.reflect.GeneratedMethodAccessor154.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) at java.lang.reflect.Method.invoke(Method.java:611) at com.ibm.team.repository.common.internal.util.ItemStore$ItemInvocationHandler.invoke(ItemStore.java:597) at com.sun.proxy.$Proxy46.getValue(Unknown Source) at com.ibm.team.workitem.client.internal.DependencyHandler$Worker.runProtected(DependencyHandler.java:51) at com.ibm.team.foundation.client.util.FoundationJob.run(FoundationJob.java:68) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53) Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot find function difference in object [object Object]. (defectage_fix2.js#18) at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3557) at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3535) at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3563) at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3582) at org.mozilla.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3646) at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2186) at org.mozilla.javascript.gen.c55._c2(defectage_fix2.js:18) at org.mozilla.javascript.gen.c55.call(defectage_fix2.js) at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:401) at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3003) at org.mozilla.javascript.gen.c55.call(defectage_fix2.js) at com.ibm.team.rtc.common.scriptengine.internal.bridge.proxy.AbstractInvocationHandler$MethodHandler$1.run(AbstractInvocationHandler.java:160) at com.ibm.team.rtc.common.scriptengine.environment.AbstractScriptEnvironment.execute(AbstractScriptEnvironment.java:74) at com.ibm.team.rtc.common.scriptengine.internal.bridge.proxy.AbstractInvocationHandler$MethodHandler.invoke(AbstractInvocationHandler.java:156) at com.ibm.team.rtc.common.scriptengine.internal.bridge.proxy.AbstractInvocationHandler.invokeGeneric(AbstractInvocationHandler.java:141) at com.ibm.team.rtc.common.scriptengine.internal.bridge.proxy.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:95) at com.sun.proxy.$Proxy63.getValue(Unknown Source) at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider.getValue(ScriptAttributeValueProvider.java:67) ... 10 more !ENTRY com.ibm.team.workitem.common 4 0 2015-07-08 18:39:42.231 !MESSAGE Error invoking work item filter 'com.ibm.team.workitem.valueproviders.CONDITION._yv7VIMmBEeSRb4PmPBgPIQ' !STACK 0 com.ibm.team.rtc.common.scriptengine.UnknownTypeException: 'com.ibm.team.workitem.DevelopmentReject' is not a constructor at com.ibm.team.rtc.common.scriptengine.environment.ScriptingHelperImplementation.getConstructor(ScriptingHelperImplementation.java:162) at com.ibm.team.rtc.common.scriptengine.ScriptUtilities$1.run(ScriptUtilities.java:30) at com.ibm.team.rtc.common.scriptengine.environment.AbstractScriptEnvironment.execute(AbstractScriptEnvironment.java:74) at com.ibm.team.rtc.common.scriptengine.ScriptUtilities.newInstance(ScriptUtilities.java:27) at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider$ProviderCall.getProvider(ScriptAttributeValueProvider.java:203) at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider$ProviderCall.<init>(ScriptAttributeValueProvider.java:188) at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider.matches(ScriptAttributeValueProvider.java:156) at com.ibm.team.workitem.common.internal.attributeValueProviders.AttributeValueProviderRegistry$SafeWorkItemFilter.matches(AttributeValueProviderRegistry.java:151) at com.ibm.team.workitem.common.internal.RequiredAttributesByConditionAdvisor.getRequiredAttributes(RequiredAttributesByConditionAdvisor.java:92) at com.ibm.team.workitem.common.internal.PropertiesManager.findRequiredAttributes(PropertiesManager.java:101) at com.ibm.team.workitem.common.internal.WorkItemCommon.findRequiredAttributes(WorkItemCommon.java:583) at com.ibm.team.workitem.ide.ui.internal.editor.presentations.presentationhandler.RequiredPropertiesHandler$RequiredUpdaterJob.runInBackground(RequiredPropertiesHandler.java:73) at com.ibm.team.jface.internal.util.UIUpdateManager$BackgroundJob.runProtected(UIUpdateManager.java:58) at com.ibm.team.foundation.client.util.FoundationJob.run(FoundationJob.java:68) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53) Comments
Donald Nong
commented Jul 19 '15, 8:52 p.m.
There are two errors.
|
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; } }); })(); |
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.