Adding child not working using Java Api
![](http://jazz.net/_images/myphoto/53329f45c9bafb46bd773c2b8c99936d.jpg)
Accepted answer
![](http://jazz.net/_images/myphoto/53329f45c9bafb46bd773c2b8c99936d.jpg)
private static class LinkWorkItemOperation extends WorkItemOperation { private IWorkItemHandle fOpposite; private IEndPointDescriptor fEndpointDescriptor; public LinkWorkItemOperation(IEndPointDescriptor endpointDescriptor, IWorkItemHandle opposite) { super("Linking Work Item", IWorkItem.FULL_PROFILE); fOpposite = opposite; fEndpointDescriptor = endpointDescriptor; } @Override protected void execute(WorkItemWorkingCopy workingCopy, IProgressMonitor monitor) throws TeamRepositoryException { IItemReference reference = IReferenceFactory.INSTANCE .createReferenceToItem(fOpposite); workingCopy.getReferences().add(fEndpointDescriptor, reference); } }Where you would call the operation with
LinkParentWorkItemOperation operationParent = new LinkWorkItemOperation( ILinkTypeRegistry.INSTANCE.getLinkType( WorkItemLinkTypes.PARENT_WORK_ITEM) .getSourceEndPointDescriptor(), linkdest); operationback.run(opposite, monitor);Opposite and linkdest being the work items.
One other answer
![](http://jazz.net/_images/myphoto/53329f45c9bafb46bd773c2b8c99936d.jpg)
you want this article from Ralph Schoon: https://rsjazz.wordpress.com/2013/11/06/creating-clm-links-with-back-link/
Please mark this answer as accepted if it helped to solve your problem.
best,
Arne
Comments
![](http://jazz.net/_images/myphoto/53329f45c9bafb46bd773c2b8c99936d.jpg)
Hello,
I couldn't find much help from this. Can you please explain.
![](http://jazz.net/_images/myphoto/53329f45c9bafb46bd773c2b8c99936d.jpg)
I am using following code to add parent
final ILinkManager linkManager = (ILinkManager)repo.getClientLibrary(ILinkManager.class);
IWorkItem wi=wiClient.findWorkItemById(parentID, IWorkItem.FULL_PROFILE, monitor);
final IReference workItemRef =
linkManager.referenceFactory().createReferenceToItem(task);
URI myURI = ItemURI.createWorkItemURI(wiClient.getAuditableCommon(), parentID);
IReference targetEndpoint = IReferenceFactory.INSTANCE.createReferenceFromURI(myURI);
final ILink newLink = linkManager.createLink(
WorkItemLinkTypes.PARENT_WORK_ITEM, workItemRef,targetEndpoint);
linkManager.saveLink(newLink, monitor);
}
Comments
sam detweiler
Aug 23 '15, 8:26 a.m.usually, this problem is because the source (from) and destination(to) workitems are backwards when you create the parent link.