In an effort to provide a bit more customization and cleaner look and feel along with all the other goodies that SPServices provides, I've been trying to get a custom comment submission from a home page that provides teaser blog entries for quick and increased collaboration.
However, in trying to post to the Comments list on the blog subsite (I believe they have the Bamboo Discussion Board Plus feature enabled), I get tje following error in the response SOAP:
However, in trying to post to the Comments list on the blog subsite (I believe they have the Bamboo Discussion Board Plus feature enabled), I get tje following error in the response SOAP:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.</faultstring><detail><errorstring xmlns="http://schemas.microsoft.com/sharepoint/soap/">Cannot access a closed Stream.</errorstring></detail></soap:Fault></soap:Body></soap:Envelope>
I've used a similar way to write to other lists for quite a while, but here's the code currently in development for this. I've added a few extra comments inline for clarification/context// Sends in id of blog post as well as the title of the post entry, URI encoded.
//I have to escape and send in encoded for ' and other special characters, which would break in the javascript
function commentPopup(id, entry){
//URI decode the post title and display in label div tag
$("#commentLbl").html(decodeURIComponent(entry));
//reset the text area for comments to blank to allow user to enter their comment
$("#divCommentForm textArea").val('');
//show modal popup to enter comments
$('#commentLbl').show();
$("#divCommentForm").show(500);
}
function submitComment (){
//grab user's comments
comment = $("#divCommentForm textArea").val();
//hide the form, then do the upload
$("#divCommentForm").hide();
//if there was a comment, show a 'thank you' message, then upload the comment
if (comment){
$("#divCommentThankYou").show();
$("#divCommentThankYou").fadeOut(4000);
uploadComment(comment);
}
}
function uploadComment(comment){
//grab comment and pass into XML function to setup for SPService to add
var updateCommentXml = get_UpdateCommentXML(comment);
//testing alert to make sure correct XML format and data was made
alert(updateCommentXml);
$().SPServices({
webURL: "/Blog",
operation: "UpdateListItems",
async: true,
listName: "Comments",
updates: updateCommentXml ,
completefunc: function(xData, Status) {
//this is where the error response keeps coming back instead of actually creating the new comment
alert(xData.responseText);
}
});
}
function get_UpdateCommentXML(comment){
var xml = '';
xml ='<Batch OnError="Continue" ListVersion="1">';
xml += '<Method ID="1" Cmd="New">';
xml += '<Field Name="Title">Comment</Field>';
//Tried with and without CDATA to see if it would help escape other characters
xml += '<Field Name="Body"><![CDATA["' + comment + '"]]></Field>';
//Used hard coded ID and Titles as well as blank, both came back with errors
xml += '<FieldRef Name="PostID" />';
xml += '<FieldRef Name="PostTitle" />';
xml += '</Method>';
xml += '</Batch>';
return xml;
}