It's all about the answers!

Ask a question

How to delete workitem programmatically

Pheneenda gadipoodi (11710) | asked Feb 03 '14, 5:25 a.m.
retagged Feb 04 '14, 7:07 a.m. by Adam Wereszczynski (92811932)


I want to delete work item using plain java api. I have used "WorkItemClient.deleteWorkitem()" method but it is not deleting the workitem.

Refer below code, I have tried passing both workitem and workitem workingcopy

IWorkItem workItem = workItemClient.findWorkItemById(Integer.parseInt(workItemId), IWorkItem.FULL_PROFILE, null);
IDetailedStatus status = workItemClient.deleteWorkItem(workItem, null);


IWorkItem workItem = workItemClient.findWorkItemById(Integer.parseInt(workItemId), IWorkItem.FULL_PROFILE, null);
IDetailedStatus status = workItemClient.deleteWorkItem((WorkItemHandle) workItem.getWorkingCopy(), null);
please let me know if I am doing anything wrong.

2 answers

permanent link
Ralph Schoon (63.3k33646) | answered Feb 18 '14, 6:46 a.m.
edited Feb 18 '14, 6:51 a.m.
This code works for me, provided the user has the permission to delete work items in the project area.
	IWorkItem workItem = workItemClient.findWorkItemById(id, IWorkItem.SMALL_PROFILE, monitor);
	IDetailedStatus status = workItemClient.deleteWorkItem(workItem, monitor);
	if (!status.isOK()) {
			throw new TeamRepositoryException("Error deleting work item",

	System.out.println("Deleted work item: " + idString + ".");
You don't require a workingcopy, workingcopy manager or anything else.

Pheneenda gadipoodi commented Feb 18 '14, 10:37 a.m.

Thanks Ralph.

That is the exact code which I have written to delete. deleteWorkItem() returning status OK, however If I open the workitem in using id in RTC or in web it is opening. Then once again if I run my program to delete same work item then findWorkItemByID() is returning NULL.

permanent link
Lauren Hayward Schaefer (3.3k11727) | answered Feb 03 '14, 7:50 a.m.

Are you getting any errors? 

I believe the user who deletes work items needs to have JazzAdmins permissions.  Can you confirm the user who is authenticated has JazzAdmins permissions?

Pheneenda gadipoodi commented Feb 03 '14, 11:02 p.m.

Thanks for your quick response

Yes, I have admin rights and I am able to delete the workitems using eclipse. However I am not able to delete using the java program, in program I am getting status OK when I try to execute delete instruction(workItemClient.deleteWorkItem(workItem, null)). 

After that I am not able to fetch that workitem using Java API method(workItemClient.findWorkItemById(Integer.parseInt(workItemId), IWorkItem.FULL_PROFILE, null)), however able to fetch using workitem query in RTC eclipse and also fetch workitem using quick search also.

Lauren Hayward Schaefer commented Feb 04 '14, 6:53 a.m.

Unfortunately, I'm not familiar enough with the delete api to understand why it wouldn't be working.  Perhaps something in this article on creation will trigger something for you:

Pheneenda gadipoodi commented Feb 18 '14, 4:29 a.m.

Thanks for your prompt response. I have already went through that page however I did not find anthing related to delete workitems please guide me to get the proper point of contact.

Lauren Hayward Schaefer commented Feb 18 '14, 6:46 a.m.

@rschoon do you have any ideas?

sam detweiler commented Feb 18 '14, 10:54 a.m.

many time the eclipse client caches things u don't wan it to..

close eclipse and reopen

note that the pgm connection and the eclipse connection to the workspace are two different connections.

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.