Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

 

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.

0 votes


Accepted answer

Permanent link

 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

1 vote

Comments

Excelent!  It is exactly what i was looking for


Thanks!
 


3 other answers

Permanent link

 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.

0 votes

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 


Permanent link

 


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. 


0 votes

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.


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



Permanent link

 

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>

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,952
× 481
× 4

Question asked: Nov 10 '21, 7:22 p.m.

Question was seen: 1,576 times

Last updated: Nov 11 '21, 6:32 p.m.

Confirmation Cancel Confirm