what I'd like to do is to create multiple data records (of one type) in one call to the server.
The solution needs to work in SharePoint 2007 and the data is stored in an XML Data Source, i.e. an XML file referred to in the respective section of the "Data Source Library" view in SharePoint Designer.
The problematic part is: 'create multiple'. Creating a single record is no problem.
What I tried (without success) so far is:
A) do what you do to create a single record multiple times, i.e.: - create one or more ASP controls, do a databind of a change to different attributes of the data record (using the proper xpath) and end it with [new], do a commit, e.g.
<asp:CheckBox runat="server" id="stageActivation{$Pos}" text=" " checked="FALSE" __designer:bind="{ddwrt:DataBind('i',concat('stageActivation',$Pos),'Checked','CheckedChanged','',concat(string($xPathWithoutLastNode), '/Stage[new]'),'@activated')}"/>
...
later based on a user's button click:
javascript: {ddwrt:GenFireServerEvent('__commit')}
Problem here: If I repeat the first part (with different id, of course) a couple of times, only the last one results in a created data record at commit time. I assume that has something to do with the timing an actual server side id is created to fill the [new] part.
B) use CSOM
Problem here: Doesn't work because I have to live with SharePoint 2007, where this does not exist. Upgrading is unfortunately not an option at this point in time and I can't wait for it.
C) use UpdateListItems of the Lists Web Service (/_vti_bin/Lists.asmx)
Problem here: If the data source on the server would be a SharePoint List, it's quite easy (tried this successfully), but I need to write to an XML Data Source. It might be possible, but I didn't find any example how this can be done if it's possible. What I'm unsure about is: - what's the listName in this case? - do I specify the XPath in the field name or somewhere else? What I tried (doesn't work and just responds with 'Internal Server Error') is:
function createNewItem(site, listName, batch)
{
var soapEnv =
"<?xml version=\"1.0\" encoding=\"utf-8\"?> \
<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/\"> \
<soap:Body> \
<UpdateListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\"> \
<listName>" + listName + "</listName> \
<updates> \
" + batch + " \
</updates> \
</UpdateListItems> \
</soap:Body> \
</soap:Envelope>";
$.ajax({
url: "http://" + site + "/_vti_bin/lists.asmx",
beforeSend: function(xhr) {
xhr.setRequestHeader("SOAPAction",
"http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
},
type: "POST",
dataType: "xml",
data: soapEnv,
error: processError,
success: processSuccess,
complete: processResult,
contentType: "text/xml; charset=utf-8"
});
}
function createFiveStages(site, listName, parentNode)
{
var batchHeader =
"<Batch OnError=\"Continue\">";
var batchFooter =
"</Batch>";
var batchItems = "";
for(i = 0; i < 5; i++)
{
batchItems +=
"<Method ID=\"" + (i + 1) + "\" Cmd=\"New\"> \
<Field Name=\"" + parentNode + "/Stage[" + (i + 1) + "]/@index\">" + (i + 1) + "</Field> \
<Field Name=\"" + parentNode + "/Stage[" + (i + 1) + "]/@activated\">False</Field> \
</Method>";
}
var batch = batchHeader + batchItems + batchFooter;
createNewItem(site, listName, batch);
}
D) do multiple round trips between server and browser using server variables and just create one item at a time
Problem: I want to avoid this, because it's unnecessary network traffic and has a big bad performance impact.
Any ideas? Can I get A or C to work, or are there other possibilities in SP2007?
Thanks in advance.