Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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.

0 votes



2 answers

Permanent link
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",
					status.getException());
	}

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

3 votes

Comments

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
Hi,

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?

0 votes

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..


close eclipse and reopen

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

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,937
× 411

Question asked: Feb 03 '14, 5:25 a.m.

Question was seen: 7,048 times

Last updated: Feb 18 '14, 10:54 a.m.

Confirmation Cancel Confirm