Delete List Item

Aug 12, 2010 at 9:03 AM

Hello, I've just used this library for 2 days and I'm really impressed to what it can do with sharepoint web services. My task is create something like Wall of facebook

However, I'm searching for a method which can be used to delete an item in a list by its ID.

Did I miss something in this library, if so please help me.

Coordinator
Aug 12, 2010 at 11:23 AM

What you're looking for is UpdateListItems, which is an operation in the Lists Web Service. If you look at the SDK for UpdateListItems, you'll see what you need to do. By setting the Cmd="Delete", you can delete list items.

Here's an example:

<Batch OnError="Continue" ListVersion="1"
ViewName="270C0508-A54F-4387-8AD0-49686D685EB2">
   <Method ID="1" Cmd="Delete">
      <Field Name='ID'>2</Field>
   </Method>
   <Method ID="2" Cmd="Delete">
      <Field Name='ID'>8</Field>
   </Method>
</Batch>

M.

Aug 13, 2010 at 2:24 AM
Edited Aug 13, 2010 at 3:09 AM

Thank you for your reply. Could you provide some real code example of how to delete multiple List Item by one function?

I tried this but it is not work:

$().SPServices({
	operation: "UpdateListItems",
	listName: 'Comments',
	batchCmd: "Delete",
	valuepairs: [["ID",cID]],
	completefunc: function (xData, Status) {
		$('#trComment'+cID).remove();				
		}
	});

Coordinator
Aug 13, 2010 at 3:31 AM

Are you getting an error? Is it not doing what you expected?  What's the "error"?  I'm assuming that you have cID set to the ID number of an existing item in the Comments list.  I think that you should specify it as a separate option (but I'm not testing, just suggesting):

$().SPServices({
	operation: "UpdateListItems",
	listName: 'Comments',
	batchCmd: "Delete",
	ID: cID,
	completefunc: function (xData, Status) {
		$('#trComment'+cID).remove();				
	}
});

M.

Aug 13, 2010 at 6:25 AM

Yep, I figured it out 3 hours ago, make me look up through some online documents :)

Thank you so much