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 (63.5k●3●36●46)
| 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
Pankaj Sharma
commented Jan 20 '16, 4:14 a.m.
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.
Ralph Schoon
commented Jan 20 '16, 4:36 a.m.
| edited Jan 20 '16, 4:37 a.m.
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.
Pankaj Sharma
commented Jan 20 '16, 8:24 a.m.
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);
|
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.