API to duplicate an WorkItem
3 answers
I'm not aware of any copy/duplicate method; however, there is an internal CopyToProjectOperation class in com.ibm.team.workitem.common.internal. Similarly there's the CopyToProjectAreaOperation class in com.ibm.team.workitem.rcp.ui.internal.wizards. The latter is the one behind the UI move/copy operation.
There is no method provided. It is not straightforward to copy a work item, especially if you copy that work item into a different project area ( you will have to resolve the attributes by identifier ).
Here is a starting point to copy the attributes:
<pre>
IAuditableClient auditableClient= (IAuditableClient) teamRepository.getClientLibrary(IAuditableClient.class);
IWorkItemCommon workItemCommon= (IWorkItemCommon) teamRepository.getClientLibrary(IWorkItemCommon.class);
fType= workItemCommon.findWorkItemType(<workItem>.getProjectArea(), <workItem>.getWorkItemType(), monitor);
fType.getCustomAttributes();
workItemCommon.findBuiltInAttributes(<workItem>.getProjectArea(), monitor);
</pre>
That will get you all the attributes. Note, not all can be copied (e.g. the Id). Additionally, if you copy the work item over project areas, you will have to resolve the id over the new project using:
<pre>workItemCommon.findAttribute(projectArea, identifier, monitor)</pre>
Finally, the comments will have to be copied separately. I know its not pretty, but it can be done cleanly
Here is a starting point to copy the attributes:
<pre>
IAuditableClient auditableClient= (IAuditableClient) teamRepository.getClientLibrary(IAuditableClient.class);
IWorkItemCommon workItemCommon= (IWorkItemCommon) teamRepository.getClientLibrary(IWorkItemCommon.class);
fType= workItemCommon.findWorkItemType(<workItem>.getProjectArea(), <workItem>.getWorkItemType(), monitor);
fType.getCustomAttributes();
workItemCommon.findBuiltInAttributes(<workItem>.getProjectArea(), monitor);
</pre>
That will get you all the attributes. Note, not all can be copied (e.g. the Id). Additionally, if you copy the work item over project areas, you will have to resolve the id over the new project using:
<pre>workItemCommon.findAttribute(projectArea, identifier, monitor)</pre>
Finally, the comments will have to be copied separately. I know its not pretty, but it can be done cleanly
Comments
Jared Camilli
Jun 04 '12, 2:07 p.m.Hi. Would someone please reply to this post? I have the same question.
If there is no "duplicateWorkItem()" method, then what's the best way to copy a work item?
Thanks.