Update \ Insert items to SharePoint List problem! - InfoPath Dev
in

InfoPath Dev

Update \ Insert items to SharePoint List problem!

Last post 12-14-2007 01:25 PM by Clay Fox. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 07-26-2007 05:55 AM

    Update \ Insert items to SharePoint List problem!

    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?????

  • 07-27-2007 04:54 AM In reply to

    Re: Update \ Insert items to SharePoint List problem!

    Hi,

    That's cool that you are using arabic hebrew symbols in your URL - my uncultured eyes have never seen that!

    I don't know exactly the problem, but I'm sure you would have to augment the UPDATE method with some kind of ID so that SharePoint knows which row you are trying to update.  Omitting this ID (you don't need it for a NEW command, anyway) makes SharePoint throw an exception that it disregards.

    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 07-28-2007 08:55 PM In reply to

    Re: Update \ Insert items to SharePoint List problem!

    Hi Matt:

     It's not Arabic... it's Hebrew (I am from Israel)!!

  • 07-29-2007 09:51 AM In reply to

    Re: Update \ Insert items to SharePoint List problem!

    I am very sorry for the mistake, I should really do my research first!

     Did you ever figure out a solution to your problem?

    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 12-05-2007 11:58 AM In reply to

    Re: Update \ Insert items to SharePoint List problem!

     Could you please let me know, where you have included the javascript in Infopath. i was trying to that but could not find a way. Please help me. Its urgent.

  • 12-14-2007 01:25 PM In reply to

    Re: Update \ Insert items to SharePoint List problem!

    Any code goes on abutton or in several other points.

    You can access the script page via a button's properties or from tools - form code.

Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.