It's all about the answers!

Ask a question

How to get Workitem attributes list


Robert Siara (821014) | asked Nov 07 '12, 8:45 a.m.
edited Nov 07 '12, 11:20 a.m. by Ralph Schoon (63.1k33645)
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.

Accepted answer


permanent link
Ralph Schoon (63.1k33645) | answered Nov 07 '12, 11:07 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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

Comments
Ralph Schoon commented Nov 07 '12, 11:20 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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

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

2 other answers



permanent link
Ralph Schoon (63.1k33645) | answered Nov 13 '12, 1:30 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.

permanent link
Robert Siara (821014) | answered Nov 12 '12, 8:00 p.m.
edited Nov 12 '12, 8:01 p.m.
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();
}

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.