Update One particular item in sharepoint list

Nov 19, 2012 at 8:13 PM

Hi,

I am using SPServices for the first time and able to know some details. Here I am trying to add some item to a list which I could do successfully. But I am not able to update a previously added row. Please help.

function UpdateTheList(){
var title_details='XSen';
var name_details='Soumya';

//THIS TO ADD
var fieldsToUpdate = "<Batch OnError='Continue' PreCalc='TRUE'><Method ID='1' Cmd='New'><Field Name='Title'>" + title_details + "</Field>" + "<Field Name='Name'>" + name_details + "</Field></Method></Batch>";

//IS THIS TO UPDATE ?? HOW CAN I SET FILTER / CRITERIA HERE...
var fieldsToUpdate1= "<Batch OnError='Continue' PreCalc='TRUE'><Method ID='1' Cmd='Update'><Field Name='Title'>" + title_details + "</Field>" + "<Field Name='Name'>" + name_details + "</Field></Method></Batch>";


$().SPServices({ 
operation: "UpdateListItems", 
async: false, 
listName: "List1", 
listProperties:"", 
updates: fieldsToUpdate1, 
newFields: "", 
deleteFields: "", 
listVersion: "", 
completefunc: function (xData, Status){alert('Done');}}); }

Coordinator
Nov 19, 2012 at 8:48 PM

You're almost there, but you have to provide either the url (for documents) or the ID (for list items) to match the existing item for an update. You're also using the options for UpdateList, not UpdateListItems.

Check out the documentation.

M.