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

How to get Workitem attributes list

Hi,

I built RTC client.
And I can get a list of custom attributes programmatically, but I do not know how to get a list of built-in attributes.

I would be grateful for your help,searched the archive threads but the answers were not clear enough for me.

0 votes


Accepted answer

Permanent link
Robert, I used this code and it has worked for me:

     private boolean printAttributesOfType(IProjectArea projectArea,
            String workItemTypeID, IProgressMonitor monitor)
            throws TeamRepositoryException {

        IWorkItemType workItemType = getWorkItemClient().findWorkItemType(
                projectArea, workItemTypeID, monitor);

        List<IAttributeHandle> builtInAttributeHandles = getWorkItemClient()
                .findBuiltInAttributes(projectArea, monitor);
        IFetchResult builtIn = getTeamRepository().itemManager()
                .fetchCompleteItemsPermissionAware(builtInAttributeHandles,
                        IItemManager.REFRESH, monitor);

        List<IAttributeHandle> custAttributeHandles = workItemType
                .getCustomAttributes();
        ;
        IFetchResult custom = getTeamRepository().itemManager()
                .fetchCompleteItemsPermissionAware(custAttributeHandles,
                        IItemManager.REFRESH, monitor);

        log("Attributes of Work Item type: " + workItemType.getDisplayName()
                + " ID: " + workItemType.getIdentifier());
        log("  Built In Attributes");
        printAttributeTypes(builtIn.getRetrievedItems(), monitor);

        log("  Custom Attributes");
        printAttributeTypes(custom.getRetrievedItems(), monitor);

        return true;
    }

Robert Siara selected this answer as the correct answer

2 votes

Comments

You would, based on the list test the work item with

workItem.hasBuiltInAttribute(attribute)
workItem.hasCustomAttribute(attribute)


2 other answers

Permanent link
My code above returns the attributes of a specific work item type. The attribute might be still missing at the work item. You would have to check it is there and create it, if not.

Your code above looks for all built in attributes for a project area and not a work item type.

2 votes


Permanent link
Firstly Thank you for such a quick response

Secondly: Is
this code really correctly returns the names and values ​​of attributes of a specific WorkItem?


for(int i = 0; i<workItemClient.findBuiltInAttributes(projectArea, monitor).size();i++){
                //resolved.getItem() returns some workItem
                com.ibm.team.workitem.common.model.IAttributeHandle handle =   workItemClient
                        .findBuiltInAttributes(projectArea, monitor).get(i);
                com.ibm.team.workitem.common.model.IAttribute attribute = (IAttribute) repository.itemManager().fetchCompleteItem(handle, IItemManager.DEFAULT, new NullProgressMonitor());
                System.out.println(attribute.getDisplayName() +" " + resolved.getItem().getValue(attribute));
            }

I built it based on the code retrieves custom attributes:

for(int i = 0; i<resolved.getItem().getCustomAttributes().size();i++){
            com.ibm.team.workitem.common.model.IAttributeHandle handle = resolved.getItem().getCustomAttributes().get(i);
            com.ibm.team.workitem.common.model.IAttribute attribute = (IAttribute) repository.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: " + resolved.getItem().getValue(attribute));
            System.out.println("Type of the custom attribute: " + attribute.getAttributeType());
            String typ  = attribute.getAttributeType();
}

0 votes

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,936
× 411

Question asked: Nov 07 '12, 8:45 a.m.

Question was seen: 8,481 times

Last updated: Nov 13 '12, 1:30 a.m.

Confirmation Cancel Confirm