Running SP 2013. I've got SPServices 2014.01 and JQuery 1.11.0 both copied to my site collection and loading in my masterpage, plus I've confirmed they're loading with the page in question. I've got a button on my list view that calls the function below. While troubleshooting, I added some alerts to see where it's breaking. All of the alerts are coming up ok, so the function itself is working. The last alert at the end is saying that the workflow guid is null, so the break seems to be that it's not finding the ID within the middle part (after the 'SPServices operation called' alert box).
function Rename(ItemURL, ItemID){
console.log("$ version:" + $.fn.jquery);
console.log("window.jQuery version:" + window.jQuery.fn.jquery);
console.log("Starting...");
var workflowDiv = 'WorkflowDiv' + ItemID
var workflowGUID = null;
//Find Workflow TemplateID for current document library
console.log("SPServices loaded? = " + ($.fn.SPServices ? "Yes" : "No") );
$().SPServices({
operation: "GetTemplatesForItem",
item: ItemURL,
debug: true,
async: false,
completefunc: function (xData, Status) {
console.log(xData.responseText);
$(xData.responseXML).find("WorkflowTemplates > WorkflowTemplate").each(function(i,e) {
// hard coded workflow name
if ( $(this).attr("Name") == "Rename" ) {
var guid = $(this).find("WorkflowTemplateIdSet").attr("TemplateId");
console.log("Variable guid set to: " + guid);
if ( guid != null ) {
workflowGUID = "{" + guid + "}";
console.log("Variable workflowGUID set to: " + workflowGUID);
}
}
});
}
});
//Show loading image
document.getElementById('wfloader').style.visibility = 'visible';
//Call Workflow
$().SPServices({
operation: "StartWorkflow",
item: ItemURL,
debug: true,
templateId: workflowGUID,
workflowParameters: "<root />",
completefunc: function() {
console.log("Finish and reload page");
//window.location.reload();
}
});
}
The end result is that the function should find the workflow called "Rename" associated with the current item, then trigger it. This was all working prior to yesterday, but I did something that broke it and I'm pulling my hair out trying to find it. The workflow itself runs fine if I manually trigger it, and I've confirmed that the workflow name is just "Rename" with no extra spaces or anything.
Anyone have any ideas what I'm doing wrong?
UPDATE: Per suggestion, I replaced the alert boxes with console logging (see updated code above). Now when I click the button while watching the console (F12 in IE10), I get the following results:
$ version:1.11.0
window.jQuery version:1.11.0
Starting...
SPServices loaded? = Yes
<?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/">Value does not fall within the expected range.</errorstring></detail></soap:Fault></soap:Body></soap:Envelope>
Finish and reload page