It's all about the answers!

Ask a question

Help setting parent/child link through API


K Shymanski (263) | asked Dec 03 '08, 3:18 p.m.
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

3 answers



permanent link
Andrea Ianni (1611916) | answered Jul 27 '10, 11:19 a.m.
This example is very useful!!!!

Thanks

Andrea

permanent link
Patrick Streule (4.9k21) | answered Dec 04 '08, 8:38 a.m.
JAZZ DEVELOPER
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

permanent link
K Shymanski (263) | answered Dec 03 '08, 9:46 p.m.
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);

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.