It's all about the answers!

Ask a question

How to get the WorkItems from a Project Area based on their type ?


Sujith Gannamaneni (1637) | asked Aug 22 '14, 2:59 p.m.
edited Aug 22 '14, 3:05 p.m.
I am trying to get all the work items which have their type as defect from a particular project area. But I'm only able to get all the work items irrespective of their type from a particular project area. Can any one please tell me how to add the type criteria and get the work items which are of type defect. Below is the code which I am working on.

Thanks.

String repoUri = "****************";
        final String userId = "****************";
        final String password = "******************";
        List<IWorkItem> defectWorkitems=new ArrayList<IWorkItem>();
        TeamPlatform.startup();
        try {
            // Login to the repository using the provided credentials
            ITeamRepository repo = TeamPlatform.getTeamRepositoryService().getTeamRepository(repoUri); repo.registerLoginHandler(new ILoginHandler2() {
                @Override
                public ILoginInfo2 challenge(ITeamRepository arg0) {
                    return new UsernameAndPasswordLoginInfo(userId, password);
                }
            });
            repo.login(new SysoutProgressMonitor());
            IProcessItemService connect = (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);
            List<IProjectArea> p = connect.findAllProjectAreas(null, new SysoutProgressMonitor());
            System.out.println("Project Areas :");
            for(IProjectArea projectArea: p){
                System.out.println(projectArea.getName());
                if(projectArea.getName().equals("********************")){
                    System.out.println("here");
                    IAuditableClient auditableClient = (IAuditableClient) repo.getClientLibrary(IAuditableClient.class);
                    IQueryClient queryClient = (IQueryClient) repo.getClientLibrary(IQueryClient.class);
                    IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(projectArea, IWorkItem.PROJECT_AREA_PROPERTY, auditableClient, null);
                    Expression expression = new AttributeExpression(attribute, AttributeOperation.EQUALS, projectArea);
                    IQueryResult<IResolvedResult<IWorkItem>> results = queryClient.getResolvedExpressionResults(projectArea, expression, IWorkItem.FULL_PROFILE);
                    while(results.hasNext(new SysoutProgressMonitor())){
                        IResolvedResult<IWorkItem> result = results.next(new SysoutProgressMonitor());
                        IWorkItem workItem = (IWorkItem) result.getItem();
                        System.out.println(workItem.getItemId());
                        if(workItem.getItemType().toString()=="Enhancement"){
                            System.out.println("here");
                            defectWorkitems.add(workItem);
                        }
                    }
                }        
}             System.out.println(defectWorkitems.size());
     } finally {
            TeamPlatform.shutdown();
        }
    }

One answer



permanent link
sam detweiler (12.5k6195201) | answered Aug 22 '14, 5:06 p.m.
see Ralphs blog on  querys
https://rsjazz.wordpress.com/2012/10/29/using-work-item-queris-for-automation/

Comments
Sujith Gannamaneni commented Aug 23 '14, 9:43 p.m.

I m getting an error while running the above code right after printing the Project Area list.

ERROR: com.ibm.team.workitem.common - Value set provider not found: com.ibm.sport.rtc.common.ComponentBrowseValueSetUtils


sam detweiler commented Aug 24 '14, 6:30 a.m.

Hm.. I have not figured out how to configure a batch application using the plain java apis to support running scripted extensions.

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.