0

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>";
JL.
  • 78,954
  • 126
  • 311
  • 459

2 Answers2

0

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.

JL.
  • 78,954
  • 126
  • 311
  • 459
0

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.

Yongwei Xing
  • 12,983
  • 24
  • 70
  • 90