Question

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>";
Was it helpful?

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.

OTHER TIPS

You don't need use the where clause to update a list item.

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

The only think you need do is to provide the ID like above.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top