It's all about the answers!

Ask a question

Capturing the date when state changes in RTC


Vijayveer Reddy (17625) | asked Dec 23 '15, 3:10 a.m.
edited Dec 23 '15, 4:18 a.m.
Hi,

We are having a field called "Defect Resolution date" in Defect work item.

We have return a dojo script to capture the current time stamp when defect work item change to Fixed state.

Its working fine....it is capturing the time stamp when defect comes to Fixed state.

However this timestamp changes when the attribute values are modified like example comments field or any change to it, in the same state "Fixed " too. This should not be the case.

It just change the date agian in the same state when ever change on field value and save operation. So is there any way i can change my script condition to achieve this.

Thanks in advance...!




dojo.provide("com.example.defectresolutiondateCalculationValueProvider");

dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date.stamp");

// --------------------------------------------------------------------------------
// Calculate the Ready For Review Date.  When a Review work item goes into Ready For Review status, then set
// the date to the current timestamp.
// If the defect has any other status, then set the Review Date to some bogus value.
// --------------------------------------------------------------------------------

(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;

dojo.declare("com.example.defectresolutiondateCalculationValueProvider", null, {
    getValue: function(attributeId, workItem, configuration) {
      
        // Log messages go to:  Eclipse client: client/eclipse/workspace/.metadata/.log
        console.log("com.example.dateCalculationValueProvider - Entry");
      
       
        // Get the current timestamp, and convert it to an ISO-8601 string

           var ModifiedDate = new Date();
    console.log("Modified Date = " +ModifiedDate);
        var ModifiedDateString= dojo.date.stamp.toISOString(ModifiedDate, {milliseconds:true, zulu:true});
    console.log("Modified Date String = " +ModifiedDateString);
 
        var ReviewStatus = workItem.getValue(WorkItemAttributes.STATE);
        console.log("com.example.dateCalculationValueProvider:  ReviewStatus: '" + ReviewStatus + "'");
       
       
               
        // If the state is Ready For Review
        if ( ReviewStatus == "NewDefectWorkflow.state.s2" )
        {
   
            return ModifiedDateString;
        }
        else
        {
       
        //var retestDate = dojo.date.stamp.toISOString(workItem.getValue("retesting_date"));

        //console.log("current constraint date is "+retestDate);

           console.log("set old date back");
           return workItem.getValue(attributeId);
          
         }
        
        console.log("com.example.dateCalculationValueProvider - Exit:  Review date returned is '" + ModifiedDateString + "'")
      
       
    }
});
})();




Comments
GURVINDER SOKHI commented Feb 01 '19, 5:45 a.m.


I am interested in automatically capturing work item state transition date too.

Did you manage to get this feature work in RTC ? If so did you use “Calculated Value” (see attached screenshot) calling into custom Java Script ? It would be great help if you are able to share the Java Script.

 

Thanks for your help in advance.

Accepted answer


permanent link
sam detweiler (12.5k6195201) | answered Dec 23 '15, 10:09 a.m.
unfortunately, in javascript, you cannot  see what the status was BEFORE.. only after..
so, your script updates the date everytime,

you only want to set the date on the transition from not fixed to fixed status.
to do that , you will have to write a server side java Participant.

see the workshop for creating extensions.
https://jazz.net/library/article/1000

Vijayveer Reddy selected this answer as the correct answer

One other answer



permanent link
Jonas Studer (207917) | answered Jan 15 '16, 7:52 a.m.
There might be 3 types of a solution for you.

1:
Easiest way to achieve what you want would be a boolean value.
You set it false in every other state and set it true when you have the wished state.

2:
You "read" the time you've setted. If there's some value in it. Don't change it.

3:
There are states and actions(Those are who changes the state).
It would be better to catch the action instead the state itself.
In that case you exactly know what state the Item had and going to have.

Comments
1
Ralph Schoon commented Jan 15 '16, 8:55 a.m. | edited Jan 15 '16, 9:00 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

In JavaScript Attribute customization, you can only see the action in conditions, where you can't use them to set an attribute.

As far as I can tell, the only way users have been able to detect a state change in calculated value providers so far was, by storing the state in a hidden custom attribute (maybe boolean works as well) and detecting the state change by comparing the value there and the new state value (which this attribute is dependent upon). Store the new state and let that trigger another script dependent on this attribute.

The other calculated attribute provider depends on that. If the value changes and the state is the one you want to count, you could save the date, I suppose. Your attribute would only be recalculate if a state changes and you could return the old date as long as the state (in the hidden attribute) is not the one you are interested in.

I have never tried that, especially because attribute customization

does not run in the visual studio client, the shell and in any automation

so, if you want something accurate, a work item save (server) follow up action is the better, more reliable choice.


Jonas Studer commented Jan 15 '16, 9:28 a.m.

Antoher Idea could be to read in the history the last entry.
There you also could detect the state change.


Ralph Schoon commented Jan 15 '16, 9:33 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I am not aware that you have access to the work item history using the attribute customization JavaScript API. As far as I am aware all you can do is read attributes - the current state.


Jonas Studer commented Jan 15 '16, 10:18 a.m.

Yep.. The History isnt direct in the workitem.
But I'm sure it's possible to get it.

But lets change to another topic.
If you're working with this struct.
com.ibm.team.workitem.web.cache.internal.WorkItemProxyFactory

Then you can do a lot more than just reading the current state.
With the following method you can see what possibilities you have.
this.workingCopyProxy.getValue({path: "attributes"}

And thats the way to get the values out of something.
this.workingCopyProxy.getValue({path: "attributes.contextId.id"});



Ralph Schoon commented Jan 15 '16, 10:39 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Please provide a working attribute customization provider (e.g. something that uses this and calculates and returns the result shown into the console or as text so you can show it in the description.


Ralph Schoon commented Jan 15 '16, 10:41 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

PS, you have my e-mail.

showing 5 of 6 show 1 more comments

Your answer


Register or to post 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.