It's all about the answers!

Ask a question

How can I get the Workitem status/state history with timestamps??!!??


Abraham Ayorinde (1113) | asked Jan 04 '17, 10:46 a.m.
closed Feb 21, 1:51 a.m. by Ralph Schoon (63.3k33646)

I want to be able to print out all the status changes with time stamps for a particular work item over the entire life of the work item.


I've patched together some code that gets all 'State handles'.(See the code and the results below)

But the thing is the results I'm getting are confusing.  I only want the history of changes to the 'Status' but I'm getting hundreds of records of state changes.

Can someone help me describe what's happening

Thanks in advance. 

**Code below
IItemManager itm = repository.itemManager(); 
 
List history = itm.fetchAllStateHandles((IAuditableHandle) workitem.getStateHandle(), monitor);
    
System.out.println("Historical Cases: " + history.size());

for(int i = history.size() -1; i >= 0; i--)
{
            IAuditableHandle audit = (IAuditableHandle) history.get(i);
       
            IWorkItem workItemPrevious = (IWorkItem) repository.itemManager().fetchCompleteState(audit,null);
       
            java.util.Date recordModifiedDate = workItemPrevious.modified();
    
            System.out.println("Record modification date: "+recordModifiedDate);
       
            System.out.println("Record history index: " + i);
       
            System.out.println("Record state: " + workItemPrevious.getState2());
}

**Code above

**Results below
Historical Cases: 24
Record modification date: 2016-11-03 13:15:55.368
Record history index: 23
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-12-07 11:22:23.399
Record history index: 22
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-12-07 11:45:17.254
Record history index: 21
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-12-13 10:59:40.571
Record history index: 20
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-12-07 10:20:09.179
Record history index: 19
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-12-12 12:40:49.932
Record history index: 18
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-12-12 15:00:43.669
Record history index: 17
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-12-13 11:02:22.155
Record history index: 16
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-12-13 11:01:13.309
Record history index: 15
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-12-13 11:13:48.806
Record history index: 14
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-11-29 08:06:25.364
Record history index: 13
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-11-02 11:26:23.938
Record history index: 12
Record state: com.ibm.team.workitem.common.model.IState:com.ibm.team.apt.story.verified
Record modification date: 2016-11-02 11:45:51.928
Record history index: 11
Record state: com.ibm.team.workitem.common.model.IState:com.ibm.team.apt.story.verified
Record modification date: 2016-12-15 10:18:14.363
Record history index: 10
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-12-15 10:16:57.417
Record history index: 9
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-12-07 10:19:46.44
Record history index: 8
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-12-07 10:21:57.642
Record history index: 7
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-12-07 10:25:47.977
Record history index: 6
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-11-29 08:06:01.403
Record history index: 5
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-11-30 12:50:40.55
Record history index: 4
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-12-07 13:48:32.403
Record history index: 3
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-11-02 12:28:21.215
Record history index: 2
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-11-02 13:11:58.679
Record history index: 1
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-12-15 10:20:01.567
Record history index: 0
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Historical Cases: 8
Record modification date: 2016-12-07 12:36:30.392
Record history index: 7
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s6
Record modification date: 2016-12-05 12:56:15.207
Record history index: 6
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s6
Record modification date: 2016-12-05 12:53:19.604
Record history index: 5
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-12-05 12:55:39.283
Record history index: 4
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-12-05 12:54:15.001
Record history index: 3
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-11-29 16:16:31.078
Record history index: 2
Record state: com.ibm.team.workitem.common.model.IState:gm.crWorkflow.state.s9
Record modification date: 2016-11-29 16:16:25.527
Record history index: 1
Record state: com.ibm.team.workitem.common.model.IState:com.ibm.team.apt.story.verified
Record modification date: 2016-12-12 15:09:24.285
Record history index: 0
**Results above

Accepted answer


permanent link
Arne Bister (2.6k12832) | answered Jan 04 '17, 5:50 p.m.
JAZZ DEVELOPER
Abraham,

a work item state change is not equal to a change in the status attribute.
If another attribute of the work item changes (i.e. a new comment gets added) without the work item changing status still a new work item state (history entry) is created.

To get just the changes to status you will likely have to parse your list to only print a history entry
if workItemPrevious.getState2() is different from the previous #.getState2()

If this answer is helpful please mark it as accepted.

- Arne
Ralph Schoon selected this answer as the correct answer

Comments
Abraham Ayorinde commented Jan 04 '17, 3:02 p.m. | edited Feb 12 '17, 6:04 p.m.

 Thanks for all the help but I've figured it out.  


This should be closed. 

But if anyone wants me to post the code I shall.


Ralph Schoon commented Feb 21, 1:55 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Another API that exposes the history is the reportable REST api: https://jazz.net/wiki/bin/view/Main/ReportsRESTAPI#Reportable_REST_API

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.