How to get stateId value from itemHIstory, using REST API (or JAVA API as well)
https://.../ccm/rpt/repository/workitem?size=10&fields=workitem/workItem[id=196902]/(itemHistory/)
Accepted answer
This prints a work item, its ID historical states and the workflow state information for each of those historical states.
3 other answers
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
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
Comments
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.
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.
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 >= 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>