It's all about the answers!

Ask a question

Set and get method for Attribute Type for "ItemList and Item"


Monali Jambhulkar (841640) | asked Sep 12 '12, 6:14 a.m.

Hi ,

I need to set and get the values of  custome attribute in RTC . Those attribute identiifers are itemList and item.

Could you please lte me know which RTC Java API can be used for the same.

Thanks

Monali

2 answers



permanent link
Lauren Hayward Schaefer (3.3k11727) | answered Sep 14 '12, 7:55 a.m.
JAZZ DEVELOPER
edited Sep 14 '12, 7:56 a.m.
Hi Monali,

The type of the value you use will need to match whatever the type of your attribute is.  For example, I created a custom attribute of type Item and then set the item type to Work Item.  So instead of calling workItem.setValue with a String "my value", I called workItem.setValue with an IWorkItem:

com.ibm.team.workitem.common.model.IAttributeHandle handle2 = workItem.getCustomAttributes().get(1);
com.ibm.team.workitem.common.model.IAttribute attribute2 = (com.ibm.team.workitem.common.model.IAttribute) teamRepository.itemManager().fetchCompleteItem(handle2, IItemManager.DEFAULT, new NullProgressMonitor())
System.out.println("The attribute id: " + attribute2.getIdentifier());
System.out.println("The attribute name: " + attribute2.getDisplayName());
System.out.println("The value of the custom attribute: " + workItem.getValue(attribute2));
//Getting the handle for work item 15
IWorkItem handleOfWorkItemToSet = getWorkItemHandle(15, teamRepository);
manager.connect(handleOfWorkItemToSet, IWorkItem.SMALL_PROFILE, progress.newChild(20));
IWorkItem workItemToSet = manager.getWorkingCopy(handleOfWorkItemToSet).getWorkItem();
workItem.setValue(attribute2, workItemToSet);

I have the following getWorkItemHandle method defined:

    /**
     * Get the work item handle associated with the given work item id number
     * @param workItemId The id number of the work item
     * @param repo The team repository
     * @return The work item handle associated with the given work item
     * @throws TeamRepositoryException
     */
    private IWorkItem getWorkItemHandle (int workItemId, ITeamRepository repo) throws TeamRepositoryException{
        IWorkItemClient workItemClient= (IWorkItemClient)repo.getClientLibrary(IWorkItemClient.class);
        IWorkItem handle= workItemClient.findWorkItemById(workItemId, IWorkItem.SMALL_PROFILE, monitor);
        if (handle == null) {
           throw new TeamRepositoryException(NLS.bind(Messages.WorkItemCommenter_UNABLE_TO_FIND_WORK_ITEM, workItemId));
        }
        return handle;
    }



Comments
Monali Jambhulkar commented Sep 14 '12, 9:15 a.m.

Hi Lauren,

We are also following the similar process for all other attribute types but we are not able to do it for only item and itemList attribute type.

Thanks


Lauren Hayward Schaefer commented Sep 14 '12, 10:17 a.m.
JAZZ DEVELOPER

Hi Monali,

The sample code I provided set the value for a custom attribute (attribute2), which was of type Item. Can you explain what problem you are hitting?


permanent link
Lauren Hayward Schaefer (3.3k11727) | answered Sep 12 '12, 7:13 a.m.
JAZZ DEVELOPER
Hi Monali,

The following snippet should get you started:
//Instead of getting the first custom attribute here, you would search through the list to find the correct one
com.ibm.team.workitem.common.model.IAttributeHandle handle = workItem.getCustomAttributes().get(0);
com.ibm.team.workitem.common.model.IAttribute attribute = (IAttribute) teamRepository.itemManager().fetchCompleteItem(handle, IItemManager.DEFAULT, new NullProgressMonitor());
System.out.println("The attribute id: " + attribute.getIdentifier());
System.out.println("The attribute name: " + attribute.getDisplayName());
System.out.println("The value of the custom attribute: " + workItem.getValue(attribute));
workItem.setValue(attribute, "new value");


Comments
Monali Jambhulkar commented Sep 14 '12, 1:51 a.m.

Hi Lauren,

We tried this approach for attribute type 'Item' but we are getting following exception while setting the attribute's value at line workItem.setValue(attribute, "new value");

java.lang.ClassCastException: java.lang.String cannot be cast to com.ibm.team.workitem.common.model.Identifier at com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl.setValue(WorkItemImpl.java:2947)

Please suggest.

Your answer


Register or 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.