It's all about the answers!

Ask a question

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

Monali Jambhulkar (841430) | 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.



2 answers

permanent link
Lauren Hayward Schaefer (3.3k11427) | answered Sep 12 '12, 7:13 a.m.
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 handle = workItem.getCustomAttributes().get(0); 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");

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 at

Please suggest.

permanent link
Lauren Hayward Schaefer (3.3k11427) | answered Sep 14 '12, 7:55 a.m.
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: handle2 = workItem.getCustomAttributes().get(1); attribute2 = ( 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;

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.


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

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?

Your answer

Register or to post your answer.