Save Work Item precondition - get Parent workitem
![](http://jazz.net/_images/myphoto/23cd3a4adc21e5c1a9def00c16d87ff8.jpg)
Is there a technique that I can use to find the Parent workitem in the Precondition on that first 'save' (when the parent relationship is first established)?
Thanks in advance,
Dave
Accepted answer
![](http://jazz.net/_images/myphoto/23cd3a4adc21e5c1a9def00c16d87ff8.jpg)
public IWorkItemHandle findParent(AdvisableOperation operation) throws TeamRepositoryException
{
Object data = operation.getOperationData();
if (data instanceof ISaveParameter) // from Workitem -> save operation
{
ISaveParameter saveParameter = (ISaveParameter) data;
IWorkItemReferences ref = saveParameter.getNewReferences();
List<IEndPointDescriptor> types = ref.getTypes();
for (IEndPointDescriptor desc : types)
{
if (desc.getId().equalsIgnoreCase("parent")) // "parent" is an RTC/Jazz string ID
{
List<IReference> refList = ref.getReferences(desc);
if (refList.size() > 0)
{
IReference iRef = refList.get(0); // Only one parent
Object obj = iRef.resolve();
if (obj instanceof IWorkItemHandle) // Only looking for Workitems.
{
return (IWorkItemHandle) obj;
}
else
return null;
}
else
return null;
}
}
}
return null;
}
6 other answers
![](http://jazz.net/_images/myphoto/23cd3a4adc21e5c1a9def00c16d87ff8.jpg)
ILinkTypeRegistry.INSTANCE.getLinkType(WorkItemLinkTypes.IMPLEMENTS_REQUIREMENT).getTargetEndPointDescriptor()
![](http://jazz.net/_images/myphoto/23cd3a4adc21e5c1a9def00c16d87ff8.jpg)
My plugins purpose is to check if my task contains a link to a requirement or not. If not, you can't save workitem, if there's a link you can save it. I finished the plugin and deployed to server. I tested on both RTC and RRC sides.
When you create a workitem through RTC web client or thick client, the plugin works. It warns user in case of a missing link. But if I try to add a workitem to a requirement with a "implemented by" link throug RRC web client, we cant save the workitem. The plugin warns me about "not having a requirement linked to the workitem". I guess linking operation bahaves differently.
Comments
![](http://jazz.net/_images/myphoto/d0f7b0b7bfc90721959d790b8a9bf79f.jpg)
there are TWO sets of data, old and proposed new..
I but you are checking OldState.. (which doesn't have the link yet) chaneg to checking NewState
![](http://jazz.net/_images/myphoto/e5e63d5878217b64611c1df9401b7cd3.jpg)
That is something to check, sa mentioned in my other answer. However, there are really links that don't trigger a participants. I am not sure if these are of the class. The inconsistent behavior in RTC and the external tools are disturbing.
![](http://jazz.net/_images/myphoto/23cd3a4adc21e5c1a9def00c16d87ff8.jpg)
I found out recently that CLM link changes don't trigger advisors or participants and filed https://jazz.net/jazz/web/projects/Rational%20Team%20Concert#action=com.ibm.team.workitem.viewWorkItem&id=228421 . This might be a situation that is similar. I am not sure. You might want to file a work item or support my work item.
On the the hand, I am wondering if you plugin looks at the right references in the saveParameter.
![](http://jazz.net/_images/myphoto/23cd3a4adc21e5c1a9def00c16d87ff8.jpg)
I took the opportunity to blog what I found about work item links in my blog: https://rsjazz.wordpress.com/2012/09/19/the-rtc-workitem-link-apilinking-workitems-to-other-elements/
It is client side only today. The restriction really is that I couldn't find a quick way to access the references of work items on the server (except in plug ins, where I have a save parameter). I found that and work on more. Currently I am struggling with finding the code to create a link on the server.