Update \ Insert items to SharePoint List problem!

L

lior

I use this code to Insert new item to a sharepint List in an InfoPath form
code (javascript):



var xmlDoc = "";
xmlDoc += "<Batch>";
xmlDoc += "<Method ID='1' Cmd='New'>";
xmlDoc += "<Field Name='Title'>" + idNode.text +"</Field>";
xmlDoc += "<Field Name='FirstName'>" + fnNode.text +"</Field>";
xmlDoc += "<Field Name='LastName'>" + lnNode.text +"</Field>";
xmlDoc += "<Field Name='Job'>" + jobNode.text +"</Field>";
xmlDoc += "<Field Name='CarNumber'>" + cnNode.text +"</Field>";
xmlDoc += "<Field Name='CarType'>" + ctNode.text +"</Field>";
xmlDoc += "<Field Name='CarColor'>" + ccNode.text +"</Field>";
xmlDoc += "<Field Name='Notes'>" + notesNode.text +"</Field>";
xmlDoc += "</Method>";
xmlDoc += "</Batch>";

soapRequest += "<?xml version='1.0' encoding='utf-8'?>";
soapRequest += "<soap:Envelope
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>";
soapRequest += " <soap:Body>";
soapRequest += " <UpdateListItems
xmlns='http://schemas.microsoft.com/sharepoint/soap/'>";
soapRequest += " <listName>" + strListName +"</listName>";
//Change here the name of the list to update
soapRequest += " <updates>" + xmlDoc + "</updates>"; //Just
specify your Batch xml variable created before
soapRequest += " </UpdateListItems>";
soapRequest += " </soap:Body>";
soapRequest += "</soap:Envelope>";




var xmlHttpRequest = new ActiveXObject("MSXML2.XMLHTTP.5.0");


//Send datas to Sharepoint. Here we're specifying headers.
Content-Length is not mandatory.
xmlHttpRequest.open("POST", "http://teutza/C5/דף
ר×שי/_vti_bin/Lists.asmx", false); //Just specify here the complete address
of the list service
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml;
charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length",1);
xmlHttpRequest.setRequestHeader("SOAPAction",
"http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
xmlHttpRequest.send(soapRequest);



This code work well and Insert new record to the SP List.

The problem is that I dont know how to use this code to Update exist record
in the list, In the xmlDoc defintion I change:

xmlDoc += "<Method ID='1' Cmd='New'>"; to be xmlDoc += "<Method
ID='1' Cmd='Update'>";

But nothing happen!!!!

What should I do?????
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top