It's all about the answers!

Ask a question

How to get IContributor objects from a WorkItem


Philipp H (5311) | 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?

Thanks

One answer



permanent link
Ralph Schoon (56.0k23642) | answered Aug 17 '16, 9:34 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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

	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
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 https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/ 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.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.

Your answer


Register or to post your answer.