How to get IContributor objects from a WorkItem
![](http://jazz.net/_images/myphoto/3904872d0aaf07fe7ab4f7aaa92231df.jpg)
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
![](http://jazz.net/_images/myphoto/3904872d0aaf07fe7ab4f7aaa92231df.jpg)
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());
Comments
![](http://jazz.net/_images/myphoto/3904872d0aaf07fe7ab4f7aaa92231df.jpg)
Thanks for your reply.
I already tried using getValue(IAttribute), but I can't seem to get from my attribute id to an IAttribute. How do I?
![](http://jazz.net/_images/myphoto/3904872d0aaf07fe7ab4f7aaa92231df.jpg)
Oh and yes I looked at https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/ but I don't have a workItemClient or a fProjectArea
![](http://jazz.net/_images/myphoto/e5e63d5878217b64611c1df9401b7cd3.jpg)
You can get the teamRepository using getOrigin(). You can get the project area from the IWorkItem. You can get the client libraries or common services (IWorkItemCommon) based on that information, depending on the context you are in, which you don't explain. This all allows to find and look up the IAttribute.
https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/ is a good summary if you use the client api.