0

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
2
  • 2
    Have you tried to console.log your guid and workflowGUID in your GetTemplatesForItem function? If the second is saying the guid is null then the first function is failing if your workflowGUID variable continues to be null. May 2, 2014 at 18:56
  • Excellent suggestion, PirateEric, though I'm not sure if I did the console logging correctly. As far as I can tell, the function is breaking when it attempts to find a workflow template with the name "Rename", even though there is definitely one there with that name.
    – Omegacron
    May 2, 2014 at 20:22

1 Answer 1

1

I thought this sounded somewhat familiar as I encountered this in the past. Surely enough I found a discussion item over on the spservice forums about it. The issue is likely the URL you are receiving and passing into the first function. It needs to be in the form of http://your.spdomain.com/sites/site/Lists/YourList/ItemID_.000

Try passing in a URL like that and you should be all set. Also, here is another reference to the proper URL.

1
  • Yep - that got me looking in the right direction. Turned out ctx.CurrentItem["FileRef"] wasn't giving me the correct URL at the beginning of the process (in the previous script that had the onClick event). After building my own path using the item ID, everything appears to be working correctly now. Thanks!
    – Omegacron
    May 2, 2014 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.