J
jupiter41
After days and days of search, test, of suffering and crying, of tears,
of great moment of hope and despair, I finally managed to find the
solution to populate data from an Infopath form to a Sharepoint list
(task list, for instance).
First of all: the example you find under /_vti_bin/Lists.asmx is really
really bad made. It's absolutly unclear. You don't need to specify an
XSL schema, and the XML file asked is the same "Batch file" you create
when you use UpdateListsItems using VB.NET. The lack of documentation
about this is really a SHAME!! Now, lady and gentlemen, there's the
final code:
function CTRL54_5::OnClick(eventObj)
{
var objField1;
objField1=XDocument.DOM.selectSingleNode("//my:myFields/my:Objet").text;
XDocument.UI.Alert(objField1);
var liste =
XDocument.DOM.selectNodes("//my:myFields/my:group15/my:Activities");
//The XML doc contains the same batch type as the VB.NET way of using
UpdateListItems
var xmlDoc = "";
//The soap request is adapted from the example in /_vti_bin/Lists.asmx
var soapRequest = "";
//Using a xmlHttpRequest allow to don't bother about the precise
formatting of the request, letting Infopath care about that.
var xmlHttpRequest;
//Here's our batch xml file. Very simple. Just add "Field" parameter
to fill more fields (here's just an example)
xmlDoc += "<Batch>";
xmlDoc += "<Method ID='1' Cmd='New'>";
xmlDoc += "<Field Name='Title'>Test</Field>";
xmlDoc += "</Method>";
xmlDoc += "</Batch>";
//Prepare SOAP request. Notice that no schema is specified. The
headers will come in the xmlHttpRequest object.
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>test</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>";
//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;
}
//Send datas to Sharepoint. Here we're specifying headers.
Content-Length is not mandatory.
xmlHttpRequest.open("POST",
"http://yoursharepointserver/_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);
}
of great moment of hope and despair, I finally managed to find the
solution to populate data from an Infopath form to a Sharepoint list
(task list, for instance).
First of all: the example you find under /_vti_bin/Lists.asmx is really
really bad made. It's absolutly unclear. You don't need to specify an
XSL schema, and the XML file asked is the same "Batch file" you create
when you use UpdateListsItems using VB.NET. The lack of documentation
about this is really a SHAME!! Now, lady and gentlemen, there's the
final code:
function CTRL54_5::OnClick(eventObj)
{
var objField1;
objField1=XDocument.DOM.selectSingleNode("//my:myFields/my:Objet").text;
XDocument.UI.Alert(objField1);
var liste =
XDocument.DOM.selectNodes("//my:myFields/my:group15/my:Activities");
//The XML doc contains the same batch type as the VB.NET way of using
UpdateListItems
var xmlDoc = "";
//The soap request is adapted from the example in /_vti_bin/Lists.asmx
var soapRequest = "";
//Using a xmlHttpRequest allow to don't bother about the precise
formatting of the request, letting Infopath care about that.
var xmlHttpRequest;
//Here's our batch xml file. Very simple. Just add "Field" parameter
to fill more fields (here's just an example)
xmlDoc += "<Batch>";
xmlDoc += "<Method ID='1' Cmd='New'>";
xmlDoc += "<Field Name='Title'>Test</Field>";
xmlDoc += "</Method>";
xmlDoc += "</Batch>";
//Prepare SOAP request. Notice that no schema is specified. The
headers will come in the xmlHttpRequest object.
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>test</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>";
//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;
}
//Send datas to Sharepoint. Here we're specifying headers.
Content-Length is not mandatory.
xmlHttpRequest.open("POST",
"http://yoursharepointserver/_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);
}