Help setting parent/child link through API
We're trying to create some child work items automatically when a particular work item type is created. The code below to create the link executes without error, but the link is not present in RTC. The code was adapted from 'Programmatic Link Creation'; note that this is being executed from a service.
In this example saveItem is the parent and newItem is the child.
...
// save new work item
workItemServer.saveWorkItem2(newItem, workItemServer.resolveWorkItemReferences(newItem, null), null);
// get references for new item
IWorkItemReferences itemReferences = workItemServer.resolveWorkItemReferences(newItem, null);
// create reference for the save item
IReference parentReference = WorkItemLinkTypes.createWorkItemReference(saveItem);
// create link type of parent for save item
ILinkType parentLink = ILinkTypeRegistry.INSTANCE.getLinkType(WorkItemLinkTypes.PARENT_WORK_ITEM);
// create link for save item to new item
itemReferences.getReferences(parentLink.getTargetEndPointDescriptor()).add(parentReference);
...
Also tried adding this to the end
// save changes
workItemServer.saveWorkItem2(newItem, workItemServer.resolveWorkItemReferences(newItem, null), null);
Any ideas or missing details?
Thanks
In this example saveItem is the parent and newItem is the child.
...
// save new work item
workItemServer.saveWorkItem2(newItem, workItemServer.resolveWorkItemReferences(newItem, null), null);
// get references for new item
IWorkItemReferences itemReferences = workItemServer.resolveWorkItemReferences(newItem, null);
// create reference for the save item
IReference parentReference = WorkItemLinkTypes.createWorkItemReference(saveItem);
// create link type of parent for save item
ILinkType parentLink = ILinkTypeRegistry.INSTANCE.getLinkType(WorkItemLinkTypes.PARENT_WORK_ITEM);
// create link for save item to new item
itemReferences.getReferences(parentLink.getTargetEndPointDescriptor()).add(parentReference);
...
Also tried adding this to the end
// save changes
workItemServer.saveWorkItem2(newItem, workItemServer.resolveWorkItemReferences(newItem, null), null);
Any ideas or missing details?
Thanks
3 answers
Figured it out, for anyone else who needs it here are the details. Took some hunting to find the link service equivalent:
ILinkService linkService = getService(ILinkService.class);
...
IItemReference parentLink = IReferenceFactory.INSTANCE.createReferenceToItem(saveItem);
IItemReference childLink = IReferenceFactory.INSTANCE.createReferenceToItem(newItem);
ILink link= ILinkFactory.INSTANCE.createLink(WorkItemLinkTypes.PARENT_WORK_ITEM, childLink, parentLink);
ILinkServiceLibrary linkServiceLibrary = (ILinkServiceLibrary)linkService.getServiceLibrary(ILinkServiceLibrary.class);
linkServiceLibrary.saveLink(link);
ILinkService linkService = getService(ILinkService.class);
...
IItemReference parentLink = IReferenceFactory.INSTANCE.createReferenceToItem(saveItem);
IItemReference childLink = IReferenceFactory.INSTANCE.createReferenceToItem(newItem);
ILink link= ILinkFactory.INSTANCE.createLink(WorkItemLinkTypes.PARENT_WORK_ITEM, childLink, parentLink);
ILinkServiceLibrary linkServiceLibrary = (ILinkServiceLibrary)linkService.getServiceLibrary(ILinkServiceLibrary.class);
linkServiceLibrary.saveLink(link);
We're trying to create some child work items automatically when a
particular work item type is created. The code below to create the
link executes without error, but the link is not present in RTC. The
code was adapted from 'Programmatic Link Creation'; note that this is
being executed from a service.
Here's a typical code snippet for work item link creation:
workItem2= (IWorkItem) workItem2.getWorkingCopy();
IWorkItemReferences references=
workItemServer.resolveWorkItemReferences(workItem2, null);
references.add(WorkItemEndPoints.CHILD_WORK_ITEMS,
WorkItemLinkTypes.createWorkItemReference(workItem1));
workItemServer.saveWorkItem2(workItem2, references, null);
--
Regards,
Patrick
Jazz Work Item Team