Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

0 votes


Accepted answer

Permanent link
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

0 votes

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.

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.


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. 

 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 log in to post 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,950

Question asked: Jan 20 '16, 2:23 a.m.

Question was seen: 1,475 times

Last updated: Jan 20 '16, 8:24 a.m.

Confirmation Cancel Confirm