I now have it working with no errors. By placing a complete function in the RestoreVersion method it stopped the SPservices error I was getting. I just commented out the action I used to verify it fixes the error and left in the complete Function in the RestoreVersion method. I also call the Method from within the GetListItems.
Here is my finshed workign code, including my CEWP elements and button that enacts the whole thing:
Here is my finshed workign code, including my CEWP elements and button that enacts the whole thing:
<script language="javascript" type="text/javascript" src="/SiteAssets/jquery.js"></script>
<script language="javascript" type="text/javascript" src="/SiteAssets/jquery.SPServices.js"></script>
<script defer type="text/javascript">
$(document).ready(function(){
var RelativeDocName="";
//alert("jquery and SPservices loaded");
//--------------------Enable or disable Restore button --------------------------
$("#Library").change(enableRestoreBttn);
$("#vGUID").change(enableRestoreBttn);
$("#dVersion").change(enableRestoreBttn);
if ($("#Library").val()=="" || $("#vGUID").val()=="" || $("#dVersion").val()==""){
$("#RestoreBttn").attr('disabled', true);
}
if ($("#Library").val()!="" && $("#vGUID").val()!="" && $("#dVersion").val()!=""){
$("#RestoreBttn").attr('disabled', false);
}
function enableRestoreBttn(){
if ($("#Library").val()=="" || $("#vGUID").val()=="" || $("#dVersion").val()==""){
$("#RestoreBttn").attr('disabled', true);
} else if ($("#Library").val()!="" && $("#vGUID").val()!="" && $("#dVersion").val()!=""){
$("#RestoreBttn").attr('disabled', false);
}
}
$("#RestoreBttn").click(RestoreOriginalVersion);
//----------------------Function to restore document first version------------------------
function RestoreOriginalVersion(){
var LibName=$("#Library").val();
var viewGUID=$("#vGUID").val();
var docVersion=$("#dVersion").val();
//alert("Library: "+LibName);
//alert("GUID: "+viewGUID);
//alert("Version: "+docVersion);
$().SPServices({
operation: "GetListItems",
webURL: "http://johnsandbox.moss.bns",
async: false,
listName: LibName,
viewName: viewGUID,
CAMLViewFields: "<ViewFields><FieldRef Name='LinkFilename' /><FieldRef Name='_UIVersionString' /><FieldRef Name='ServerUrl' /></ViewFields>",
CAMLQueryOptions: "<QueryOptions><ViewAttributes Scope='Recursive'/></QueryOptions>",
cacheXML: true,
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
var docName = $(this).attr("ows_LinkFilename");
var docCurrentVersion = $(this).attr("ows__UIVersionString");
RelativeDocName = ("http:\/\/johnsandbox.moss.bns"+$(this).attr("ows_ServerUrl"));
//alert("RelativeDocName: "+RelativeDocName);
DoRestore(RelativeDocName,docVersion);
}); //---------closing of Data response function
} //----------closing of complete function
}); //------ end of capturing Client folder data and closing of SPServices function
alert("All documents in the view entered have been restored to the version requested");
} //----end of RestoreOriginalVersion
//-----------------------call Restore
function DoRestore(x,y){
$().SPServices({
operation: "RestoreVersion",
fileName:x,
fileVersion:y,
completefunc: function(xData,Status){
//alert(x+" Has been restored to version "+y);
}
}); //------ end of RestoreVersion SPServices function
}
}); //------end of document ready
</script>