How to access custom attribute Contributer List
![]()
Hello Team,
I am trying to access all users assigned in a contributor list using JAVA API, I am using following code:
IWorkItemCommon workItemService = param.getSaveOperationParameter().getAuditableCommon().getPeer(IWorkItemCommon.class);
r = iac.resolveAuditable((IWorkItemHandle)ir.resolve(),IWorkItem.FULL_PROFILE, null);
IAttribute attribute= workItemService.findAttribute(operation.getProcessArea().getProjectArea(),"assigned_to_tasks", monitor);
List<icontributorhandle> list = (List<icontributorhandle>) r.getValue(attribute);
System.out.println("*******list************"+list); System.out.println("*******list.toString************"+list.toString());
for (Iterator iterator = list.iterator(); iterator.hasNext(); ) { IContributor contributor= (IContributor)iterator.next(); System.out.println("*******contributor.getName()************"+contributor.getName()); System.out.println("*******contributor.getUserId()************"+contributor.getUserId());
}
But this is not working, Kindly help |
Accepted answer
![]()
Ralph Schoon (61.8k●3●36●43)
| answered Jan 20 '16, 2:40 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
1. getPeer() is deprecated. As a server operation use getService(IWorkItemCommon.class);
2. This code works for me in A RTC WorkItem Command Line Version 3.0 : Object current = getWorkItem().getValue(iAttribute); if (!(current instanceof List<?>)) { error } List<?> currentList = (List<?>) current; Pankaj Sharma selected this answer as the correct answer
Comments Thank you very much Ralph
Would you please add the full code snippet for the same
That is pretty much all the code. The rest of the code would not help you at all, because I do something quite different and the code is relatively complex.
![]() FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
PS: If you set up your environment for debugging as explained in the workshop and posts here: https://rsjazz.wordpress.com/2015/09/30/learning-to-fly-getting-started-with-the-rtc-java-apis/ , you can see what is going on easily enough and see what you get.
Thanks Ralph!!
This worked
IRepositoryItemService repositoryItemService = getService(IRepositoryItemService.class);
r = iac.resolveAuditable((IWorkItemHandle)ir.resolve(),IWorkItem.FULL_PROFILE, null);
IAttribute attribute= workItemService.findAttribute(operation.getProcessArea().getProjectArea(), "assigned_to_COSI_tasks", monitor);
List<IContributorHandle> list = (List<IContributorHandle>) r.getValue(attribute);
for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {
IContributorHandle contributorHandle= (IContributorHandle)iterator.next();
IContributor contributor = (IContributor) repositoryItemService.fetchItem(contributorHandle, null);
|