How to get IContributor objects from a WorkItem
Hi everyone,
I have a custom WorkItem with custom attributes which contain contributors (users).
Each attribute is a role.
Now I want to detect when you change which users get added to which attribute(role) via an server extension.
I have the new and the old state of the workitem.
My question is now: How do I access the contributors in those attributes?
Thanks
One answer
You get the value of the attribute like for any attribute. What you get back can be casted to something. IContributor or IContributorHandle. It is easy enough to use instanceof and debugging to see what you get.
Note, you always want to use the interface and not the implementation class.
There are multiple examples here https://rsjazz.wordpress.com/ . I am pretty sure I provided the links already.
Start here: https://rsjazz.wordpress.com/2015/09/30/learning-to-fly-getting-started-with-the-rtc-java-apis/ . Understanding and Using the RTC Java Client API explains what you just ask. And https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/ explains it a bit deeper. https://rsjazz.wordpress.com/2015/11/03/a-rtc-workitem-command-line-version-3-0/ has code to get and set these attributes and also list attributes of this kind.
getValue returns an object so
Note, you always want to use the interface and not the implementation class.
There are multiple examples here https://rsjazz.wordpress.com/ . I am pretty sure I provided the links already.
Start here: https://rsjazz.wordpress.com/2015/09/30/learning-to-fly-getting-started-with-the-rtc-java-apis/ . Understanding and Using the RTC Java Client API explains what you just ask. And https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/ explains it a bit deeper. https://rsjazz.wordpress.com/2015/11/03/a-rtc-workitem-command-line-version-3-0/ has code to get and set these attributes and also list attributes of this kind.
getValue returns an object so
if (!(value instanceof IContributorHandle)) {
throw new WorkItemCommandLineException(
"Convert Contributor - Incompatible Type Exception: "
+ value.toString());
}
IContributor contributor = (IContributor) getTeamRepository()
.itemManager().fetchCompleteItem((IContributorHandle) value,
IItemManager.DEFAULT, getMonitor());