It's all about the answers!

Ask a question

Java API extending - create a new work item and associate with a change set

Peter Moraza (481924) | asked Aug 21 '13, 4:44 p.m.

I have code based on which delivers files to a stream and creates a new change set. I want to create a new work item and associate that work item with the new change set. provides an example of creating a new work item, but I need to understand how to link the work item with the change set. A brief example would help greatly

There are many related questions in the Forum, I apologize in advance if I've overlooked an earlier answer or example. Thanks!

Peter Moraza

Accepted answer

permanent link
Ralph Schoon (62.7k33643) | answered Aug 22 '13, 4:53 a.m.
You can find some examples on for example

You might also want to look at , , and some other posts that talk about creating and modifying work items.

Peter Moraza selected this answer as the correct answer

Peter Moraza commented Aug 27 '13, 6:38 p.m.

Thanks Ralph for the excellent examples. I am able to create a Change Set and Work Item, and I have the following code (based on your examples) which tries to link Work Item to  Change Set. But when I open the Work Item in the Jazz GUI, the Links tab does not contain any reference to the Change Set (or anything else).

WorkItemWorkingCopy workingCopy = createWorkItem(repo, prjareahndl, monitor);
IItemType iit = cs1.getItemType();
IItemHandle iih = iit.createItemHandle(cs1.getItemId(), cs1.getStateId());
IItemReference reference = IReferenceFactory.INSTANCE.createReferenceToItem(iih);
IEndPointDescriptor endpoint = LinkTypeRegistry.INSTANCE.getLinkType(WorkItemLinkTypes.CHANGE_SET).getTargetEndPointDescriptor();
workingCopy.getReferences().add(endpoint, reference);

If I pass IItemHandle to createWorkItem method I get "InternalRepositoryException: Links of this type may only be modified by the defining component." when trying to save the IWorkItem.

Peter Moraza commented Aug 27 '13, 8:40 p.m.

I had not saved the WorkItemWorkingCopy after linking the Change Set and Work Item. After doing that and also changing WorkItemLinkType to  RELATED_CHANGE_MANAGEMENT the Link tab now contains a nice link to the Change Set. Thanks Ralph Schoon for pointing me in the right direction, and also for the instructions on configuring RTC for API development. Your articles are great!

Your answer

Register or to post your answer.