It's all about the answers!

Ask a question

How can I delete "copies" and "copied from" from my work items? Maybe using the Java API?


Edwin Guenthner (28177) | asked Feb 28 '13, 4:38 a.m.
edited Feb 28 '13, 4:39 a.m.

Hello there,

we had to create a huge amount of epics/user stories lately; and unfortunately our admin did not allow us to create "team specific" work item templates.

So many of us used the "duplicate" feature on work items to save some typing. That works fine ... but in the end ... you end up with many work items that have useless (therefore distracting) "copies" resp. "copied from" links. I really would like to get rid of those. 

Long story short: is there any way to do that (obviously the UI doesnt allow it)? I put together some java code that allowed me to fix the summary string of some work items; but I couldnt find any way to delete these "duplications artifacts". Any idea, anybody?

Accepted answer


permanent link
Edwin Guenthner (28177) | answered Feb 28 '13, 8:32 a.m.
edited Feb 28 '13, 8:35 a.m.

OK, found the answer myself. The API I used is deprecated, but it worked when running against RTC3.
The code snippet below provides the means to check if a given work item has a "copies" link; and if so, that is removed. Note: RTC is really cool here - removing all the "copies" links ... will also result in all your "copied from" links being gone afterwards.

    void fix(IWorkItem workItem) throws TeamRepositoryException {
IWorkItemWorkingCopyManager mgr = workItemClient.createWorkingCopyManager(userName, true);
try {
mgr.connect(workItem, IWorkItem.FULL_PROFILE, monitor);
WorkItemWorkingCopy workingCopy = mgr.getWorkingCopy(workItem);
removeCopiesReference(workingCopy);
mgr.save(new WorkItemWorkingCopy[] { workingCopy }, monitor);
} finally {
mgr.disconnect(workItem);
}
}

void removeCopiesReference(WorkItemWorkingCopy workItem) throws TeamRepositoryException {
IWorkItemReferences allReferences = workItem.getReferences();
List<IEndPointDescriptor> endPointTypes = allReferences.getTypes();
for (IEndPointDescriptor endpoint : endPointTypes) {
List<IReference> references = allReferences.getReferences(endpoint);
for (IReference finalRef : references) {
IWorkItemHandle h = (IWorkItemHandle) finalRef.resolve();
if (h == null) continue;
IWorkItem w = workItemClient.resolveWorkItem(h, IWorkItem.FULL_PROFILE, monitor);
if (endpoint.getDisplayName().equals("Copies")) {
monitor.subTask("Removing 'copies' link from ID: " + workItem.getWorkItem().getId() + " (target was): " + w.getId());
allReferences.remove(finalRef);
}
}
}
}
Ralph Schoon selected this answer as the correct answer

Comments
Michael A. commented Jul 29 '14, 8:59 a.m.

Hi Edwin,

I am currently facing the same problem with work item copies links.

Would you be so kind and share your Java project with me? I would highly appreciate it.

Thanks
Michael


Edwin Guenthner commented Jul 29 '14, 9:39 a.m. | edited Jul 29 '14, 9:42 a.m.

Actually the most important code is already posted; but if you drop me an email to edgue at web dot de I will send you the missing parts.

One other answer



permanent link
Shuhichi Saitoh (20059) | answered Jul 01 '15, 10:37 p.m.
I just have the same issue and found another option myself (for RTC 5.0.x / RTC 6.0).

We can use CSV export/import for workitems to remove the "Copied from" Link (and Copies to link as well).

1. Using Eclipse Client, export Workitem ID and Copied From link info as csv file.
Such like
ID,Copied from
10,#3

2. Remove the value of "Copied from" in csv and save the file.
ID, Copied from
10,

3. Import worrkitems from csv file using "Update matched Work Item" and "Replace existing links with newly imported values" options.

Hope this helps.


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.