It's all about the answers!

Ask a question

How to obtain the value of a custom contributor field via a RTC participant plugin?


Angela Borchard (701020) | asked Jul 14 '15, 5:48 a.m.
edited Jul 14 '15, 5:52 a.m.

Hello,

I have a work item with a custom field (of type Contributor) called:

   Requested By:

If for example, this field is set to "John Smith", how can I get the name of the user which is set in the work item via a RTC participant plugin?

/**
 * Gets the value of a Work Item (Contributor (User)) attribute.
 */
public String getAttributeValue_Contributor(String attributeID) throws TeamRepositoryException
{
   String returnValue = "";
   IAttribute attribute = workItemServer.findAttribute(workItem.getProjectArea(), attributeID, monitor);
  
   Object value = workItem.getValue(attribute);
      
   // ???
   returnValue = contributor.getName();
   return returnValue;
}

Thanks!

 

Accepted answer


permanent link
Angela Borchard (701020) | answered Jul 14 '15, 8:02 a.m.
edited Jul 14 '15, 8:06 a.m.
Thanks Ralph.

I have it working now :-)


import com.ibm.team.repository.common.IContributor;
import com.ibm.team.repository.common.IContributorHandle;
import com.ibm.team.repository.service.IRepositoryItemService;
-----------------------------------------------------------
IRepositoryItemService itemService = getService(IRepositoryItemService.class);
-----------------------------------------------------------   
  /**
   * Gets the value of a Work Item (Contributor (User)) attribute.
*
*/
public String getAttributeValue_Contributor(String attributeID) throws TeamRepositoryException {
String returnValue = "";

IAttribute attribute = workItemServer.findAttribute(workItem.getProjectArea(), attributeID, monitor);

IContributorHandle contributorHandle = (IContributorHandle) workItem.getValue(attribute); IContributor contributor = (IContributor) itemService.fetchItem(contributorHandle, null);

      returnValue = contributor.getName();
      return returnValue;    }

Ralph Schoon selected this answer as the correct answer

One other answer



permanent link
Ralph Schoon (63.0k33645) | answered Jul 14 '15, 6:06 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Jul 14 '15, 6:11 a.m.
Do a getValue()
Test if the instance of the object is an IContributorHandle, cast to the IContributorHandle, resolve the contributor from the handle. See https://rsjazz.wordpress.com/2014/05/26/only-owner-can-close-workitem-advisor/

This is true for almost all the values. You have to always cast the data and it is easy enough to look at what it is in a debugging session. Also see https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/

Your answer


Register or to post your answer.