It's all about the answers!

Ask a question

Adding child not working using Java Api


Sudipto Sarkar (631443) | asked Aug 18 '15, 7:20 a.m.
Hi,

 I tried adding parent to a workitem. It worked.But when I go to the parent workitem, I cant see the child. Am I missing something.

Regards,
Sudipto

Comments
sam detweiler commented 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.

Accepted answer


permanent link
Ralph Schoon (63.5k33646) | answered Aug 27 '15, 9:34 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Creating a work item to work item link would look like

	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.
Sudipto Sarkar selected this answer as the correct answer

Comments
Sudipto Sarkar commented Aug 27 '15, 11:13 a.m.

Thanks a lot Ralph. It worked.

One other answer



permanent link
Arne Bister (2.6k12832) | answered Aug 21 '15, 12:20 p.m.
JAZZ DEVELOPER
Hi,

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
Sudipto Sarkar commented Aug 27 '15, 7:35 a.m.

Hello,

 I couldn't find much help from this. Can you please explain.


Sudipto Sarkar commented Aug 27 '15, 8:23 a.m.

 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);
    }

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.