It's all about the answers!

Ask a question

How to get the links from a specific state of the work item ?

Arshad Adavani (231220) | asked Jan 30 '17, 11:36 a.m.
edited Jan 30 '17, 11:37 a.m.

Hello All,

I am trying to fetch changeset links present in a work item for all its states. For E.g. say I have added a changeset link to a work item 123 when it is in IN PROGRESS state and say I add one more changeset to the same work item when it is in Closed state.

I am retrieving all the work item states through its history. Something like below:

 IItemManager itm = teamRepository.itemManager();
            List history = itm.fetchAllStateHandles((IAuditableHandle) workItem.getStateHandle(), monitor);
            for (int i = history.size() - 1; i >= 0; i--)
                IAuditableHandle audit = (IAuditableHandle) history.get(i);
               // Below line fetches me different states of the work item one by one through its history.
                IWorkItem workItemPrevious = (IWorkItem) teamRepository.itemManager().fetchCompleteState(audit, null);

What I am trying to achieve :
For each state of the work item I am trying to fetch its changeset links. In the above E.g. for work item 123,
It should give output as:
IN PROGRESS : 1 changeset (I store its UUID)
Closed : 2 changesets

But for whichever state I try to access a work items changeset links, it always give me the same results. It gives the latest changeset links for all the states.

I use below code to fetch a work item's changeset links:

final IWorkItemCommon workItemCommon = (IWorkItemCommon) iTeamRepository
        final IWorkItemReferences references = workItemCommon.resolveWorkItemReferences(workItem, iProgressMonitor);
        final List<IEndPointDescriptor> refTypes = references.getTypes();

        final List<IChangeSet> changeSets = new ArrayList<IChangeSet>();

        for (final IEndPointDescriptor endPointDescriptor : refTypes)

            if (endPointDescriptor.getLinkType()

                final List<IReference> refList = references.getReferences(endPointDescriptor);
                for (final IReference reference : refList)
                    final IChangeSetHandle csh = (IChangeSetHandle) reference.resolve();

                    final IChangeSet changeSet = (IChangeSet) iTeamRepository.itemManager()
                            .fetchCompleteItem(csh, IItemManager.DEFAULT, iProgressMonitor);
                    if (changeSet != null)



Can someone help me here ?

Geoffrey Clemm commented Jan 30 '17, 2:32 p.m.

The only way I can imagine that you'd be able to determine this information is if you could obtain the exact time each change set link was added-to/removed-from the work item, and then correlate that sequence with the times that the work item changed state.  If you cannot find a way to get those times, then the information you want is probably not computable.  

Arshad Adavani commented Jan 31 '17, 2:46 a.m. | edited Jan 31 '17, 2:57 a.m.

Hi Geoffrey Clemm,

Thanks for your response. This can be definitely achieved by computing time.
But I was a little disappointed after seeing that there is an option to go to the previous state of the work item but not everything can be fetched from its previous state!
Do you think this part of the API has to be improved?

Arshad Adavani commented Feb 01 '17, 2:05 a.m.

Also is there a way to know if some link was ADDED or REMOVED from the work item?

Be the first one to answer this question!

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.