It's all about the answers!

Ask a question

How to get the workitems from iteration or how to filter out the workitems so that it belongs to a particular iteration?


Anirban Roy (1318) | asked Jun 14 '17, 2:19 a.m.

 i am able to fetch only 100 workitems but i am not able to fetch all the latest workitems..also i cannot get the contributors as well as target name.it always appears in the form of object.

i have used the below code:

IProcessItemService processItemService = (IProcessItemService)repository.getClientLibrary(IProcessItemService.class);
List<IProjectArea> projectArea = processItemService.findAllProjectAreas(null, null);
Iterator<IProjectArea> iter = projectArea.iterator();
IQueryResult<IResolvedResult<IWorkItem>> results;
IWorkItemClient workItemClient = (IWorkItemClient)repository.getClientLibrary(IWorkItemClient.class);
IQueryClient queryClient = workItemClient.getQueryClient();
IAuditableClient auditableClient = (IAuditableClient)repository.getClientLibrary(IAuditableClient.class);
while(iter.hasNext()){
IProjectArea area = (IProjectArea)iter.next();
IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(area, IWorkItem.PROJECT_AREA_PROPERTY, auditableClient, null);
// Get the CurrentIeration 
Expression expression = new AttributeExpression(attribute, AttributeOperation.EQUALS, area);
int sizeLimit = 250;
//queryClient.getResolvedExpressionResults(area, expression, IWorkItem.FULL_PROFILE).setLimit(sizeLimit);
IQueryResult<IResolvedResult<IWorkItem>> results1 = queryClient.getResolvedExpressionResults(area, expression, IWorkItem.FULL_PROFILE);
/// UnResolved Items
results1.setLimit(Integer.MAX_VALUE);
//results.setLimit(Integer.MAX_VALUE);
List<IResolvedResult<IWorkItem>> page =  results1.nextPage(null);
results1.setPageSize(250);
Iterator<IResolvedResult<IWorkItem>> iterResult = page.iterator();
 
while(iterResult.hasNext()){
IResolvedResult<IWorkItem> resolvedResult = iterResult.next();
IWorkItem workItem = resolvedResult.getItem();
if(area.getName().equals("XXXX"))
{
System.out.println("Project Area: " + area.getName() + " ID: " + workItem.getId() + " Name: "                                 + workItem.getHTMLSummary() + "Description:" +workItem.getDuration());
System.out.println(workItem.getHTMLDescription()+ " Owner :"+workItem.getOwner());
IIterationHandle iterationHandle = workItem.getTarget();

/IContributorHandle ct=workItem.getOwner();
for (IIterationHandle handle :results1.){
IAttribute currentAttribute= (IAttribute) handle;
IContributor contributor = (IContributor) repository.itemManager() 
               .fetchCompleteItem(handle, IItemManager.DEFAULT, null); 
       String userID=contributor.getUserId(); }
/
        System.out.println(" WorkItem Target Area: " + workItem.getTarget());
       
List<?>history=
repository.itemManager().fetchAllStateHandles((IAuditableHandle)workItem.getStateHandle(), null);
if(history.size() == 0){
continue;
}
}
else
{
break;
}


can u citte me what am i doing wrong.Also i cannot resize the results.
Please help me.

One answer



permanent link
Ralph Schoon (63.5k33646) | answered Jun 14 '17, 8:54 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

This is how the expression would look like:

        URI uri = URI.create(projectAreaName.replaceAll(" ", "%20"));
        IProjectArea projectArea = (IProjectArea) processClient
                .findProcessArea(uri, null, null);
        if (projectArea == null) {
            System.out.println("Project area not found.");
            return false;
        }

    IAuditableCommon auditableCommon = (IAuditableCommon) teamRepository
            .getClientLibrary(IAuditableCommon.class);

    DevelopmentLineHelper devLineHelper = new DevelopmentLineHelper(teamRepository, monitor);
    IIteration targetIteration = devLineHelper.findIteration(projectArea, Arrays.asList(iteration.split("/")), DevelopmentLineHelper.BYLABEL);

    IQueryableAttribute attribute = QueryableAttributes.getFactory(
            IWorkItem.ITEM_TYPE).findAttribute(projectArea,
            IWorkItem.PROJECT_AREA_PROPERTY, auditableCommon, monitor);
    Expression inProjectArea = new AttributeExpression(attribute,
            AttributeOperation.EQUALS, projectArea);
    IQueryableAttribute plannedFor = QueryableAttributes.getFactory(
            IWorkItem.ITEM_TYPE).findAttribute(projectArea,
            IWorkItem.TARGET_PROPERTY, auditableCommon, monitor);
    Expression isPlannedFor = new AttributeExpression(plannedFor,
            AttributeOperation.EQUALS, targetIteration);

    Term typeinProjectArea = new Term(Term.Operator.AND);
    typeinProjectArea.add(inProjectArea);
    typeinProjectArea.add(isPlannedFor);

the development line helper to find an iteration from a string representation encoded as path relative to the timeline like e.g. "Main Development/Release 1.0/Sprint 2" can be found in https://rsjazz.wordpress.com/2015/06/11/creating-plans-with-the-plain-java-client-api/ or the work item command line on said blog.

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.