Search code examples
sharepointmosswindows-sharepoint-servicescaml

How to update a sharepoint list item via web services using a where clause?


I would like to update a list item using SharePoint and am stuggling to find 1 decent CAML example.

Here is what I want to do, in SQL my query would look something like this

update [table] set field='value' where fieldID = id;

so this would mean I have 1 item in a list I would like to update 1 field on given the ID of that listitem.

I've tried this, but it doesn't work:

batchElement.InnerXml = "<Method ID='1' Cmd='Update'>" +
            "<Field Name='DeliveryStatus'>" + newStatus.ToString() + "</Field>" +
            "<Where><Eq><FieldRef Name='ID' /><Value Type='Text'>" + id + "</Value></Eq></Where></Method>";

Solution

  • I'll add this answer for the community, although it might not answer all your questions.

     batchElement.InnerXml = "<Method ID='1' Cmd='Update'>" +
                    "<Field Name='ID'>" + id + "</Field>" + 
                "<Field Name='DeliveryStatus'>" + newStatus.ToString() + "</Field></Method>";
    

    It seems the first field you specify is the where clause.

    I have no idea how you would do any advanced filtering with this (nots or exclusions or in clauses or ranges). But hope this basic info helps.