It's all about the answers!

Ask a question

How to get stateId value from itemHIstory, using REST API (or JAVA API as well)


Marcelo Bilezker (4619) | asked Nov 10 '21, 7:22 p.m.
edited Nov 10 '21, 7:25 p.m.

 

I am using EWM 7.0.2

If I run this on a workItem using REST API:
:
https://.../ccm/rpt/repository/workitem?size=10&fields=workitem/workItem[id=196902]/(itemHistory/)

I get the workItemHistory of workItem 196872. And i get this:

<workitem Version="1.0.0" rel="next" href="https://...l/ccm/rpt/repository/workitem?id=_Kq4-IEJNEey5E-m8MK5izA&fields=workitem%2FworkItem%5Bid%3D196872%5D%2F%28itemHistory%2F%29&size=10&pos=10">
<workItem>
<itemHistory>
<uniqueId>c047b1efb868e59aab35350cd22e0179</uniqueId>
<reportableUrl>https://.../ccm/rpt/repository/workitem/workItem/id/196872</reportableUrl>
<itemType>com.ibm.team.workitem.WorkItem</itemType>
<stateId>_CJPtoQwdEeyZIZVQuvzHnQ</stateId>
<itemId>_s9uYpvYDEeulzYpB_Y0gYw</itemId>
<contextId>_PBXKMN2nEeutoJyYHvgVaA</contextId>
<modified>2021-09-02T12:38:57.914-0600</modified>
<predecessor>_BwzYcgwdEeyZIZVQuvzHnQ</predecessor>


My question is if there is a way to get the literal value of stateId, instead of the String "_CJPtoQwdEeyZIZVQuvzHnQ" 

Also a Java API solution is ok.

Accepted answer


permanent link
Ralph Schoon (63.1k33645) | answered Nov 11 '21, 11:02 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 This prints a work item, its ID historical states and the workflow state information for each of those historical states.


Marcelo Bilezker selected this answer as the correct answer

Comments
Marcelo Bilezker commented Nov 11 '21, 11:56 a.m.

Excelent!  It is exactly what i was looking for


Thanks!
 

3 other answers



permanent link
Ralph Schoon (63.1k33645) | answered Nov 11 '21, 2:39 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 That stateId does represent the historical state of the work item and not the workflow state of a work item. There is no string representation for it in any API. If you get that historical state of the work item, you could get the workflow state of that version of the work items history.


Comments
Ralph Schoon commented Nov 11 '21, 2:46 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

The work item workflow state of a work item can be accessed in the reportable REST api using com.ibm.team.workitem.State see  https://jazz.net/wiki/bin/view/Main/ReportsRESTAPI#com_ibm_team_workitem_State 


permanent link
Marcelo Bilezker (4619) | answered Nov 11 '21, 9:58 a.m.

 


You point out that: 
 If you get that historical state of the work item, you could get the workflow state of that version of the work items history.

My question is how i get each workflow historical state you say I could get.

When using the workflow of the workItem, using JAVA API, i get an array with the possible values of states the workitem can be, not the states the workitem has had.
Additionally, in the page you recommended: 
there is this definition:

itemHistory (type: com.ibm.team.workitem.WorkItem, maxOccurs: unbounded). A collection of zero or more WorkItem elements, representing the entire history of the work item. Each state the work item has ever been in is reflected in this history list. 
So, it should be possible to see each of the states a workItem has been. 



Comments
Ralph Schoon commented Nov 11 '21, 10:34 a.m. | edited Nov 11 '21, 10:36 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

You use the wrong API if you get the workflow state definitions.

A WorkItem is an IAuditable and each state of it is stored and accessible, You can get the predecessor(max 2). The work item state ID is the vaalue _CJPtoQwdEeyZIZVQuvzHnQ from above. The item has an ID as well and the ID and the State ID select the version of the artefact using the IAuditableCommon or IAuditableServer, if I remember correctly. You can get the predecessor item state as well as get states in other ways.

Once you have a work item in the state you want, you can get the attribute values of that state of the work item. E.g. the workflow state. Using that you can then get the display value.

I have touched that in the Java API. I assume that the reportable REST API might expose this as well, but I do not know for sure.  
  


Ralph Schoon commented Nov 11 '21, 10:39 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 itemHistory (type: com.ibm.team.workitem.WorkItem, maxOccurs: unbounded). A collection of zero or more WorkItem elements, representing the entire history of the work item. Each state the work item has ever been in is reflected in this history list.


This implies you can get the history states of a work item and maybe even get each state.



permanent link
Marcelo Bilezker (4619) | answered Nov 11 '21, 6:32 p.m.

 

I just found how to do the same using JAVA API
I share it in case someone needs it

IWorkItem workItem = workItemClient.findWorkItemById(id, IWorkItem.FULL_PROFILE, monitor);
    System.out.println("Last modified date: "+workItem.modified()+"\n");

IItemManager itm = teamRepository.itemManager(); 
List history = itm.fetchAllStateHandles((IAuditableHandle) workItem.getStateHandle(), monitor);
System.out.println("Record history details:-");
for(int i = history.size() -1; i &gt;= 0; i--){
    IAuditableHandle audit = (IAuditableHandle) history.get(i);
    IWorkItem workItemPrevious = (IWorkItem) teamRepository.itemManager().fetchCompleteState(audit,null);
    Date recordModifiedDate = workItemPrevious.modified();
    System.out.println("Record modification date: "+recordModifiedDate);
}</i></code>
</pre>

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.