It's all about the answers!

Ask a question

How to access custom attribute Contributer List


Pankaj Sharma (40349) | asked Jan 20 '16, 2:23 a.m.
edited Jan 20 '16, 2:30 a.m.
 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


permanent link
Ralph Schoon (59.7k23643) | 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


Ralph Schoon commented Jan 20 '16, 4:30 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.

Anyway, you iterate the list, cast the result to IContributorHandle (check instenceof first) resolve the contributor handle.

You can download the code from the post above and look into com.ibm.js.team.workitem.commandline.commands.ExportWorkItemsCommand.calculateContributorListAsString(Object, String), if you want to.



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.

If you don't set up for debugging, I would stay away from trying to write extensions. 


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


Register or to post your answer.