Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

0 votes



3 answers

Permanent link
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);

0 votes


Permanent 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

0 votes


Permanent link
This example is very useful!!!!

Thanks

Andrea

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,952

Question asked: Dec 03 '08, 3:18 p.m.

Question was seen: 9,061 times

Last updated: Dec 03 '08, 3:18 p.m.

Confirmation Cancel Confirm