views:

137

answers:

1

I have a scenario where I need to update a list item, but I don't know the internal ID of the list item - hence the following won't work for me:

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

Instead I have another field in the list called ProcessID:

So I would like to update the delivery status where ProcessID = X

Is this possible using SharePoint web services.

One solution I was thinking of is to first do a select for the ID based on the ProcessID - then update based on this ID, but this seems like a crazy solution, surely the inventors of MOSS CAML would have provided a way to update a list item by some means of a where clause, or using another field for filtration rather than just plain old ID?

Thanks

+1  A: 

I don't believe you can do an UPDATE WHERE. You will need to get all the items matching your given ProcessID in order to get each of the individual item IDs.

Since you're using web services, one way to make this more efficient is to make sure you set the ViewFields property when you perform your select in order to limit it to only the columns you are interested in (in this case, ID).

Example:

XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");
XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");

ndQueryOptions.InnerXml = "<ViewAttributes Scope='Recursive' />";
ndViewFields.InnerXml = "<FieldRef Name='ID' />";
ndQuery.InnerXml = query;
Kit Menke
@Kit, thank you for the confirmation. You know SharePoint really sucks.
JL
Heh it definitely has flaws. Good luck :)
Kit Menke