Function does not fire

Jul 6, 2011 at 10:44 AM

Could someone please tell me why this alert returns 'undefined'. the path to my list is correct and the name of the workflow is the same as what is shown in the Name field of the Workflow Information page in SPD. The alert in the function to show the responseXML never fires.

alert ("Workflow template ID: "+ getWorkflowTemplateId("http://xxx.yyy.com/corp/Policies/DelegateAuthority/Lists/Delegations/"));

function getWorkflowTemplateId(itemURL){
//get GUID for Workflow, eliminates need to change code everytime the workflow changes
 $().SPServices({
   operation: "GetTemplatesForItem",
   item: itemURL,
   async: false,
   completefunc: function (xData, Status) {
     $(xData.responseXML).find("WorkflowTemplates > WorkflowTemplate").each(function(i,e) {
     alert(xData.responseXML.xml);
       // hard coded workflow name
       if ( $(this).attr("Name") == "Notify Delegate" ) {             
         var guid = $(this).find("WorkflowTemplateIdSet").attr("TemplateId");       
         if ( guid != null ) {
           workflowGUID = "{" + guid + "}";
           alert ("workflow guid" + workflowGUID);
           }
         }
       });
   }
 });

};

TIA
Dean

Coordinator
Jul 6, 2011 at 11:28 AM
Edited Jul 6, 2011 at 2:03 PM

Dean:

I don't see anything obvious. I'd add some alerts inside the getWorkflowTemplate function before and after the call to GetTemplatesForItem and make sure that the function is being called and receiving the proper parameter. You can also debug in Firebug or the Developer Tools in IE.

M.

Jul 6, 2011 at 1:50 PM

Marc, i'm using the IE 8 Dev Toolbar, when I put a breakpoint on the $().SPServices line, and add some watches, I get the following:

completefunc 'completefunc' is undefined Error

  itemURL "http://parsharesites.parsons.com/corp/Policies/DelegateAuthority/Lists/Delegations/" String

  xData.responseXML.xml 'xData' is undefined Error

  GetTemplatesForItem 'GetTemplatesForItem' is undefined Error

I'm using jQuery 1.5.2 and SPServices 0.6.1.

Any idea what would be causing these types of errors? I thought i was doing something simple, but have messed something up somehow. All of the other calls to SPServices on this page are working fine.

TIA
Dean

Coordinator
Jul 7, 2011 at 4:46 AM

Dean:

I'm really not sure what's going on. The undefined errors that you are getting don't make much sense unless you're missing a closing quote or a comma or something.

M.

Dec 15, 2011 at 3:29 PM

I was experiencing a problem getting this function to work (not exactly the same symptoms though) until I added a record identifier to the itemURL. For example "http://somesite.com/mysite/mylist/" would not work, but http://somesite.com/mysite/mylist/16_.000 worked fine where the "16" was an existing record ID in the list and the "_.000" suffix was something I found in another discussion forum.  When I open my list in SharePoint Designer I see what appear to be files in my list directory...one file for every record in the list and each named with the record ID followed  by this "_.000", so I see a correlation but am completely unfamiliar with this taxonomy or structure of this data.

It seemed like this function should work with just a list description (e.g. return all the workflows for a given list) until I remembered that lists can contain different content types and, I think content types can have different workflows from other content types in the same list (does that sound right?).

I'm looking through the documentation to try and discover a better description of the "itemURL" parameter requirement, which might have saved me some time.

Thanks very much for creating this library and making it available!