SP List Randomness Posting from Form - InfoPath Dev
in

InfoPath Dev

SP List Randomness Posting from Form

Last post 02-07-2008 07:02 AM by Clay Fox. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 02-07-2008 05:41 AM

    • scb05
    • Not Ranked
    • Joined on 02-07-2008
    • Posts 1

    SP List Randomness Posting from Form

    Hi Everyone,

     I have a real challenge...

     My Infopath form posts "new items" & "updates existing items" on random but fixed records.  Say Starlink codes 105, 1104, 1109, 1140 all work, but 101, 109, 1105, 1106, 1107 do not.  The randomness appears with no pattern of records in the SP List I'm posting or updating, but if i change the records with 109 to 105, they then work.  I've recreated the list, wiped the list, ensured the Starlink is text/string, etc....  just cant seem to crack it.  I also character by characted reviewed the SoapRequest and they are identical when comparing when it work with when it doesn't.  The only thng that changes are the Starlink and the Title.

    Has anyone heard of random success of code?  I'm surely missing something and apologies for my ineffecient/low skill use of code - partly due to my non-full time programming skills and partly due to troubleshooting/simplicfication.

     Thanks for any insights.

     

    function btnUpdate::OnClick(eventObj)
    {

    var dbData = XDocument.GetDOM("FilterQuery");

    var loop = XDocument.DOM.selectNodes("//my:System").length;
    var dbloop = dbData.selectNodes("/xml/rs:data/z:row" ).length;

    var x;
    var soapRequest;
    var xmlHttpRequest;
    var xmlDoc;
    var FoundID; //ID of existing record
    var HowPost;
    var WhichMethod;

    //loop through the System repeating table and post records to SP List 

    for (x=0;x<loop;x++) {   // *********************** Loop Start***************

    xmlDoc = ""; 
    soapRequest = "";
    xmlHttpRequest = "";
    xmlDoc += "<Batch>";
    HowPost = "<Method ID='1' Cmd='New'>";
    WhichMethod = "New system";
    // The following loop looks to the existing data from the 2nd datasource query contained in a repeating table
    // matching Application with the System table.  If found, sets the ID (SP List Record ID of existing Application) and CMD=Update then breaks the loop

    for (y=0;y<dbloop;y++) 
    {
     if (XDocument.DOM.selectNodes("//my:System/my:Application")[x].text == dbData.selectNodes("/xml/rs:data/z:row/@ows_Application")[y].text) {
      HowPost = "";
      FoundID = dbData.selectNodes("/xml/rs:data/z:row/@ows_ID")[y].text;  //query record ID
      HowPost = "<Method ID='1' Cmd='Update'>";
      HowPost+= "<Field Name='ID'>" + FoundID + "</Field>";
      WhichMethod = "Updated";
      y = dbloop;
      }
    }

    if (XDocument.DOM.selectNodes("//my:System/my:Application")[x].text >"") {  //do not allow blank rows
     xmlDoc += HowPost;
     xmlDoc += "<Field Name='Title'>" + XDocument.DOM.selectSingleNode("//my:locName").text + "</Field>";
     xmlDoc += "<Field Name='Starlink'>" + XDocument.DOM.selectSingleNode("//my:locIDNumber").text + "</Field>"; 
     xmlDoc += "<Field Name='Region'>" + XDocument.DOM.selectSingleNode("//my:txtRegion").text + "</Field>";
     xmlDoc += "<Field Name='Application'>" + XDocument.DOM.selectNodes("//my:System/my:Application")[x].text + "</Field>";  
     xmlDoc += "<Field Name='Vendor'>" + XDocument.DOM.selectNodes("//my:System/my:Vendor")[x].text + "</Field>";
     xmlDoc += "<Field Name='Product'>" + XDocument.DOM.selectNodes("//my:System/my:Product")[x].text + "</Field>";
     xmlDoc += "<Field Name='Release'>" + XDocument.DOM.selectNodes("//my:System/my:Release")[x].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>" + XDocument.DOM.selectSingleNode("//my:ListName").text + "</listName>";  
     soapRequest += " <updates>" + xmlDoc + "</updates>";  
     soapRequest += " </UpdateListItems>";
     soapRequest += " </soap:Body>";
     soapRequest += "</soap:Envelope>";

     //objXMLHttp. Just a nice try&catch to deal with eventual problems.
     try {
      var xmlHttpRequest = new ActiveXObject("MSXML2.XMLHTTP.5.0");
     }
     catch(ex){
      XDocument.UI.Alert("Could not create MSXML2.XMLHTTP.5.0 object.\r\n" + ex.number + " - " + ex.description);
      return false;
     }

    //Sharepoint Posting
     xmlHttpRequest.open("POST", XDocument.DOM.selectSingleNode("//my:ListURL").text, false);  
     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);
     XDocument.UI.Alert(XDocument.DOM.selectSingleNode("//my:locIDNumber").text+ ": " + WhichMethod + " " + XDocument.DOM.selectNodes("//my:System/my:Application")[x].text + " submit is successful.");
    } // end if
    }  // loop

    // Application.ActiveWindow.Close();

    }

     

    Any insight???

    Thanks!

  • 02-07-2008 07:02 AM In reply to

    Re: SP List Randomness Posting from Form

    Welcome.

    So you are updating a SP list not a Document Library. Have you reviewed some of the methods here?  If you search on CAML you can find some posts.

    I have not done this in code.

    I would look at the source data, although I guess you have said that just changing the title allows it to work.  Strange. Hopefully someone else will have an answer.

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