How to delete workitem programmatically
Hi,
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);
and
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
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", status.getException()); } System.out.println("Deleted work item: " + idString + ".");You don't require a workingcopy, workingcopy manager or anything else.
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?
Comments
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.
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: https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation.
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.
@rschoon do you have any ideas?
many time the eclipse client caches things u don't wan it to..