It's all about the answers!

Ask a question

How to get IContributor objects from a WorkItem

Philipp H (53314) | asked Aug 17 '16, 7:43 a.m.
edited Aug 18 '16, 3:47 a.m.
 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?


One answer

permanent link
Ralph Schoon (62.7k33643) | answered Aug 17 '16, 9:34 a.m.
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 . I am pretty sure I provided the links already.
Start here: . Understanding and Using the RTC Java Client API explains what you just ask. And explains it a bit deeper. 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());

Philipp H commented Aug 18 '16, 1:40 a.m.

 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?

Philipp H commented Aug 18 '16, 2:12 a.m.

 Oh and yes I looked at but I don't have a workItemClient or a fProjectArea

Ralph Schoon commented Aug 18 '16, 3:05 a.m. | edited Aug 18 '16, 3:10 a.m.

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. is a good summary if you use the client api.

Your answer

Register or to post your answer.