It's all about the answers!

Ask a question

Get all work items from project

Jérémy Friant (10711) | asked Oct 02 '14, 12:21 p.m.

I would like to retrieve all work items from a project. 
I found a method on this forum which allows to do, but the problem is that I try to get a ITeamRepository object and it is null.

could someone unblock me?

My code is :

public class Moniteur extends AbstractService implements IOperationParticipant {

private IWorkItem wi;
private IProgressMonitor monitor;
public void run(AdvisableOperation operation,
IProcessConfigurationElement participantConfig,
IParticipantInfoCollector collector, IProgressMonitor monitor)
throws TeamRepositoryException {
if (data instanceof ISaveParameter) 
wi = (IWorkItem) ((ISaveParameter) data).getNewState(); 
if (wi != null)
IWorkItem workingCopy = getFreshCopyWorItem();
IProjectAreaHandle ipah = workingCopy.getProjectArea();
IProjectArea ipa = (IProjectArea)getItemService().fetchItem(ipah,null);
IQueryDescriptor query = findPersonalQuery(ipa, "All Work Items", monitor);

public IQueryDescriptor findPersonalQuery(IProjectArea projectArea, 
String queryName, IProgressMonitor monitor)
throws TeamRepositoryException {
// Get the required client libraries
ITeamRepository teamRepository = (ITeamRepository)projectArea.getOrigin();
IWorkItemClient workItemClient = (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);
IQueryClient queryClient = workItemClient.getQueryClient();
// Get the current user.
IContributor loggedIn = teamRepository.loggedInContributor();
IQueryDescriptor queryToRun = null;
// Get all queries of the user in this project area.
List queries = queryClient.findPersonalQueries(projectArea.getProjectArea(), loggedIn,QueryTypes.WORK_ITEM_QUERY,IQueryDescriptor.FULL_PROFILE, monitor);
// Find a query with a matching name
for (Iterator iterator = queries.iterator(); iterator.hasNext();) {
IQueryDescriptor iQueryDescriptor = (IQueryDescriptor);
if (iQueryDescriptor.getName().equals(queryName)) {
queryToRun = iQueryDescriptor;
return queryToRun;

public IWorkItem getFreshCopy(IWorkItem workItem, IProgressMonitor monitor) throws TeamRepositoryException {
return getWorkItemServer().findWorkItemById(workItem.getId(), IWorkItem.FULL_PROFILE, monitor);

public IWorkItemServer getWorkItemServer() {
        return super.getService(IWorkItemServer.class);
public IRepositoryItemService getItemService(){
return super.getService(IRepositoryItemService.class);

public IWorkItem getFreshCopyWorItem() throws TeamRepositoryException{
IWorkItem wiFreshCopy = getFreshCopy(wi, monitor);
return (IWorkItem) wiFreshCopy.getWorkingCopy();

Best regards


Accepted answer

permanent link
Ralph Schoon (63.2k33646) | answered Oct 07 '14, 7:16 a.m.
See and Jeremy's comment and my answer to it underneath the post.
Ralph Schoon selected this answer as the correct answer

Nayeem M commented Mar 27 '15, 6:20 p.m. | edited Mar 27 '15, 6:20 p.m.

 Ralph , 
Is it possible to get work item used to checkin a file/Changeset 
For Exaple if file has been checked in by a Developer  most recently using work item 123456 .. Need to get the work item number.. 
Using scm show history  command we can get the Change Set details,but not the work item number.

 scm show history -r $URL -u $userId -P $pwd -w $ws --component icdp_core_as /source/common/Adapters/com/bac/icdp/consumer/common 
Change sets: 
  (1539) ----$ Json "Lenderview_ForwardFits" 03-Feb-2015 07:35 AM 
  (1259) ----$ Joshi, issue fix." 26-Jun-2014 05:17 AM 
  (1260) ----$ Dinesh "changed and added new" 16-May-2014 05:24 AM 
There is additional history available before this point. 

Can i get the Work Item used for the Change set using JAVA or SCM? 
  (1539) ----$ Json "Code review changes" 03-Feb-2015 07:35 AM 

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.