views:

1570

answers:

3

I want to delete an item in a list when it matches some critera using UpdateListItems web service. I dont know the ID of the list item that I want to delete but do know the criteria.

For example in SQL I could do:

DELETE FROM listName WHERE LastName='Bauer' AND FirstName='Jack'

How would you write a Batch Element to do this?

Update

Would it be something like this?

<Batch PreCalc='TRUE' OnError='Continue'>
  <Method ID='1' Cmd='Delete'>
    <Field Name='LastName'>Bauer</Field>
    <Field Name='FirstName'>Jack</Field>
  </Method>
</Batch>

Is the ID for the Method or the ID of the thing you wish to delete?

Update

I have tried the following code and the error that is returned is

Invalid URL Parameter

The URL provided contains an invalid Command or Value. Please check the URL again.

My guessing is that it is not possible to do without the ID...

A: 

I am not that familiar with using the web services, but I assume there is one for searching. Using the API you would create an SPQuery and use CAML to get the list items you wanted to remove.

Chrisb
I am not sure on whatthe caml should look like...
John
+2  A: 

As an addition to ChrisB's answer (formatting a CAML query in a comment didn't seem to work out), you'd make the query something like this:

SPQuery query = new SPQuery();
query.Query = "<Where><And>"+
  "<Eq><FieldRef Name='LastName'/><Value Type='Text'>Bauer</Value></Eq>"
  "<Eq><FieldRef Name='FirstName'/><Value Type='Text'>Jack</Value></Eq>"
  "</And></Where>";
SPListItemCollection items = list.GetItems(query);

(this is the object model specification, but it extends naturally into the webservices call)

Then you'd loop through the listitems and build up your batch.

Paul-Jan
Are you saying that I have my critera i.e Jack BaureQuery the list with the information I have to get the ID'sWith the ID's I get create my batch scriptRun the batch script to deleteI see how this would work and the end goal would be the same it just seems a bit long way to do it.
John
Almost. You actually need both the ID and the Filename from the inial query. You then then fill your batch with both the ID and the FileRef field. Yes, kinda elaborate, but as the batch element doesn't support filtering you are stuck with a two-step approach anyway.
Paul-Jan
A: 

This does not look possible.

My way round this was to query the list and get the id's. Loop for the response pull out the id's then create a method for each ID to delete it.

John