It's all about the answers!

Ask a question

Getting work Items through Plain Java API

Melanie Finke (7721520) | asked Mar 05 '12, 9:47 a.m.

I try to get work Items of a specific project area through the plain Java API.

I managed to get all project areas with the following code:

// repo is a ITeamRepository
IProcessItemService connect = (IProcessItemService) repo

List<IProjectArea> p = connect.findAllProjectAreas(null, monitor);

Afterwards I'd like to get all WorkItems of a project area. How can I do this?

I am working with Plain Java Client Libraries Version

Best regards

Accepted answer

permanent link
Steve Gates (9134) | answered Mar 05 '12, 4:06 p.m.
I used the following code to get the work items associated with each project area:

auditableClient = (IAuditableClient) repository.getClientLibrary(IAuditableClient.class);
IQueryClient queryClient = (IQueryClient) repository.getClientLibrary(IQueryClient.class);

IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(currProject, IWorkItem.PROJECT_AREA_PROPERTY, auditableClient, null);
Expression expression = new AttributeExpression(attribute, AttributeOperation.EQUALS, currProject);
IQueryResult<IResolvedResult<IWorkItem>> results = queryClient.getResolvedExpressionResults(currProject, expression, IWorkItem.FULL_PROFILE);

In my code, currProject would be the IProjectArea pointer to the current project as you loop through the List of project areas p in your code.

The IQueryResult object 'results' then contains a list of IResolvedResult records with all of the work items for that project you can iterate through and find properties for each work item.

Hope this helps.
Melanie Finke selected this answer as the correct answer


Mathieu Defianas commented Dec 17 '14, 10:34 a.m.

This answer is very perfect if I create a new java client program.
However, how can I obtain the same results (I would to search some workitems) on a server side program ? I cannot use this code using the component ITeamRepository because this method is not available on the server-side.
In fact, when I click on Save, I would like to search some workitems to execute some actions ...
Thanks for your help

Ralph Schoon commented Dec 17 '14, 11:22 a.m.

To run a query on the server, you can use IQueryCommon which is a common service - in  fact, you can probably use it on the client as well. The rest should look like in or

How to create work items was just recently explained here:

Mathieu Defianas commented Dec 17 '14, 11:35 a.m.

Thanks Ralph.
I have understood this point : I must use IQueryCommon ...
But I don't understand how I can create or get this object from my "Save" action ?

Moreover, this link is very interesting :
But, I try to resolve this 2 lines without success :
IWorkItemServer workItemServer = getService(IWorkItemServer.class);
IQueryCommon queryService= getService(IQueryCommon.class);


Mathieu Defianas commented Dec 17 '14, 11:38 a.m. | edited Dec 17 '14, 11:39 a.m.

About workItemServer , I have found solution.
I must use auditableCommon created with this code :

Object data = operation.getOperationData();
ISaveParameter param = (ISaveParameter) data;
auditableCommon = param.getSaveOperationParameter().getAuditableCommon();

Ralph Schoon commented Dec 17 '14, 11:43 a.m.

You get it using

fWorkItemCommon = getService(IWorkItemCommon.class);

You can only use getService if your class extends for example
public class MyParticipant extends AbstractService implements
        IOperationParticipant {

See examples such as on that blog.

Mathieu Defianas commented Dec 17 '14, 12:28 p.m.

Thanks a lot Ralph !
My code can be compiled !!!!
now I try to add the extension bloc on the plugin configuration but it fails because I use operationsAdvisors instead of operationParticipants (in your example)

I have a warning message on the xml plugin configuration : Elements "prerequisites" is not legal for "extensionsService" ...
Have you already used prerequisites with operationsAdvisors ?
Thanks in advance

Mathieu Defianas commented Dec 17 '14, 12:46 p.m.

I have modified my plugin to operationParticipants instead of operationsAdvisors and it is the same situation ...
Elements "prerequisites" is not legal for "extensionsService" ... 
I don't understand why ???

sam detweiler commented Dec 17 '14, 12:56 p.m.

I get the same warning, but it works

Ralph Schoon commented Dec 18 '14, 2:44 a.m. | edited Dec 18 '14, 2:46 a.m.

The warning is normal and does not create problems. If you leave the prerequisites out, you do. The schema should be adjusted, I think.

I think the Extensions Workshop also mentions the warning is normal. It is not related to participants or advisors. You get it in both.

Please open a new question if you have a question.

There are also advisors as well as participants published on you will see, they all have the same issue - just a warning only however.

showing 5 of 10 show 5 more comments

5 other answers

permanent link
Melanie Finke (7721520) | answered Mar 06 '12, 4:46 a.m.

thank's for the answer. Now I get all WorkItems. Is it possible to get only the work Items with e.g. type defect?

I tried it with the following code, but still get all Work Items.

IAttributeVariable<String> variable = new WorkItemTypeVariable("defect");


IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE) .findAttribute(currProject, IWorkItem.PROJECT_AREA_PROPERTY, auditableClient, monitor);

Expression expression = new VariableAttributeExpression(attribute,
AttributeOperation.EQUALS, variable);

IQueryResult<IResolvedResult<IWorkItem>> results = queryClient
.getResolvedExpressionResults(currProject, expression,

Is there a way to do this?

Best regards

permanent link
pugazhenthi samidurai (26423742) | answered Mar 12 '12, 6:22 a.m.

I am new to RTC.

could you able to given code for fetching work items from plain java api.



permanent link
Kelvin Lui (51299) | answered Mar 26 '12, 1:04 p.m.

I am trying to query a list of workitem base certain criteria:


The query works fine until I try to add the filter of the workitem state.
The query returns null object. Could someone shed some light how to generate the query to look up list of workitem base on its state?


IQueryableAttribute stateAttribute = findAttribute(teamRepository, projectArea, IWorkItem.STATE_PROPERTY, monitor);
AttributeExpression workItemStateTypeExpression = new AttributeExpression(stateAttribute, AttributeOperation.EQUALS, "Open");


Code snippet:

IQueryableAttribute projectAreaAttribute= findAttribute(teamRepository, projectArea, IWorkItem.PROJECT_AREA_PROPERTY, monitor);
AttributeExpression projectAreaExpression= new AttributeExpression(projectAreaAttribute, AttributeOperation.EQUALS, projectArea);

IQueryableAttribute categoryAttribute = findAttribute(teamRepository, projectArea, IWorkItem.CATEGORY_PROPERTY, monitor);
AttributeExpression categoryExpression = new AttributeExpression(categoryAttribute, AttributeOperation.EQUALS, category);

IQueryableAttribute workItemTypeAttribute = findAttribute(teamRepository, projectArea, IWorkItem.TYPE_PROPERTY, monitor);
AttributeExpression workItemTypeExpression = new AttributeExpression(workItemTypeAttribute, AttributeOperation.EQUALS, WorkItemType.getIdentifier());

IQueryableAttribute stateAttribute = findAttribute(teamRepository, projectArea, IWorkItem.STATE_PROPERTY, monitor);

AttributeExpression workItemStateTypeExpression = new AttributeExpression(stateAttribute, AttributeOperation.EQUALS, "Open");

/* //Owner is Kelvin Lui"
IQueryableAttribute ownerAttribute = findAttribute(teamRepository, projectArea, IWorkItem.OWNER_PROPERTY, monitor);
AttributeExpression ownerTypeExpression = new AttributeExpression(ownerAttribute, AttributeOperation.EQUALS, "Kelvin Lui" );

System.out.println(" ownerAttribute.getAttributeType()" + ownerAttribute.getAttributeType() + " "+
ownerAttribute.getDisplayName() + " " + ownerAttribute.getIdentifier());*/

/*//WorkItem ID
IQueryableAttribute idAttribute = findAttribute(teamRepository, projectArea, IWorkItem.ID_PROPERTY, monitor);
//AttributeExpression idExpression = new AttributeExpression(idAttribute, AttributeOperation.EQUALS, "57320" );
//new AttributeExpression(idAttribute, AttributeOperation.EQUALS, "57320" );
//System.out.println("ownerTypeExpress: "+ownerTypeExpression.getValue()+ " "+ ownerTypeExpression.getAttributeIdentifier());

//Build the Query by doing an AND Operation among the 3 above sub-queries
Term term= new Term(Operator.AND);

/* IQueryClient queryClient = (IQueryClient) teamRepository.getClientLibrary(IQueryClient.class);<IResolvedResult<IWorkItem>> result =
queryClient.getResolvedExpressionResults(projectArea, term, IWorkItem.FULL_PROFILE);

// Evaluate Query

IQueryCommon queryService= getQueryCommon(teamRepository);
//ItemProfile<IWorkItem> profile= this.getProfile(projectAreaAttribute).createExtension(IWorkItem.CREATOR_PROPERTY);
//IQueryResult<IResolvedResult<IWorkItem>> result= queryService.getResolvedExpressionResults(projectArea, term, profile);
IQueryResult<IResolvedResult<IWorkItem>> result= queryService.getResolvedExpressionResults(projectArea, term, IWorkItem.FULL_PROFILE);

//Add All Results in a list and return that list
List<IWorkItem> matchingWorkItems= new ArrayList<IWorkItem>(result.getResultSize(monitor).getTotalAvailable());
while (result.hasNext(monitor)) {

permanent link
Sarath Shasikumar (1759) | answered Mar 27 '13, 1:30 a.m.
 private List<IWorkItem> getWorkItems( IIteration sprint, String projectId ) throws TeamRepositoryException
      IProjectAreaHandle iProjectAreaHandle = (IProjectAreaHandle) getProjectArea( projectId ).getItemHandle();
      IQueryClient queryClient = (IQueryClient) getTeamRepository().getClientLibrary( IQueryClient.class );
      IAuditableClient auditableClient = (IAuditableClient) getTeamRepository().getClientLibrary(
            IAuditableClient.class );
      IQueryableAttributeFactory queryableAttributeFactory = QueryableAttributes.getFactory( IWorkItem.ITEM_TYPE );
      IQueryableAttribute targetProperty = queryableAttributeFactory.findAttribute( iProjectAreaHandle,
            IWorkItem.TARGET_PROPERTY, auditableClient, null );
      Expression sprintEqulas = new AttributeExpression( targetProperty, AttributeOperation.EQUALS, sprint );
      IQueryableAttribute isArchived = queryableAttributeFactory.findAttribute( iProjectAreaHandle,
            IWorkItem.ARCHIVED_PROPERTY, auditableClient, null );
      Expression notArchived = new AttributeExpression( isArchived, AttributeOperation.EQUALS, false );
      Term expression = new Term( Operator.AND );
      expression.add( sprintEqulas );
      expression.add( notArchived );
      IQueryResult<IResolvedResult<IWorkItem>> queryResult = queryClient.getResolvedExpressionResults(
            iProjectAreaHandle, expression, IWorkItem.FULL_PROFILE );
      List<IWorkItem> workItems = new ArrayList<IWorkItem>( queryResult.getResultSize( getProgressMonitor() )
            .getTotalAvailable() );
      while (queryResult.hasNext( getProgressMonitor() ))
         IResolvedResult<IWorkItem> resolvedResult = getProgressMonitor() );
         IWorkItem workItem = resolvedResult.getItem();
         workItems.add( workItem );
      return workItems;

permanent link
Bastian W (216) | answered Oct 05 '15, 9:24 a.m.
edited Oct 05 '15, 9:41 a.m.
Hi all,

can someone share or attach the whole source-code for getting ALL WorkItems without predefined queries? My Idea behind is to list all project areas and to list all worktimes for every project areas.

The first step is done! I get all my project areas in a customized way...but now i'm trying to get the workitems and that doesn't work with the help of the tutorials.

That's why I need the source to see the imports, main-class and the other methods. Always there is something missing or i am not able to include your codes.

Best regards!

Ralph Schoon commented Oct 05 '15, 10:04 a.m.

Your answer

Register or to post your answer.