Here is the dataview side of things that launches jQuery and SPServices (obviously the RequestListName is replaced with the actual list name):
Again, any help to clear up my confusion on SPServices here would be appreciated.
<a href="#">
<xsl:attribute name="onclick">
<xsl:text>javascript:StartWorkflow('</xsl:text>
<xsl:value-of select="@EncodedAbsUrl" disable-output-escaping="yes"/>
<xsl:text>','</xsl:text>
<xsl:value-of select="@ID" disable-output-escaping="yes"/>
<xsl:text>','RequestListName','emailTest');</xsl:text>
</xsl:attribute>
Email Me</a>
My javascript function is pulling in all parameters as string objects, but I am not sure if that causes issues or not with the SPServices functions. And I slightly modified my script but I am still getting an undefined error on xData.responseXML in the RunWorkflow function:function StartWorkflow(ItemURL, ItemID, ListName, DesiredWorkflow) {
var id = "";
$().SPServices({
operation: "GetList",
listName: "RequestListName",
async: false,
completefunc: function (xData, Status) {
id = $(xData.responseXML).find("List").attr("ID").toString();
}
});
//Get list Id from current page
if (id) {
this.guid = new SP.Guid(id);
var context = SP.ClientContext.get_current();
var lists = context.get_web().get_lists();
var list = lists.getById(this.guid);
//Set workflows variable to load and be accessible in callbacks
this.workflows = list.get_workflowAssociations();
context.load(this.workflows);
context.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed));
}
function onQuerySucceeded(sender, args) {
var enumerator = this.workflows.getEnumerator();
while (enumerator.moveNext()) {
var workflow = enumerator.get_current();
if (workflow.get_enabled() && workflow.get_allowManual()) {
var workflowName = workflow.get_name();
if (workflowName == DesiredWorkflow){
var workflowGuid = '{' + workflow.get_id().toString() + '}';
//alert(workflowName + " ..... " + workflowGuid);
RunWorkflow(ItemURL, ItemID, workflowGuid);
}
}
}
}
function onQueryFailed(sender, args) {
alert('Unable to retrieve workflows: ' + args.get_message());
}
}
function RunWorkflow(ItemURL, ItemID, workflowGuid) {
var loadingImage = 'Loader' + ItemID;
var workflowDiv = 'WorkflowDiv' + ItemID;
var workflowParams = "<root />";
//Show our loading image
document.getElementById(loadingImage).style.visibility = 'visible';
$().SPServices({
operation: "StartWorkflow",
async:true,
item: ItemURL,
templateId: workflowGuid,
workflowParameters: workflowParams,
completefunc: function (xData, Status) {
if(Status != "error"){
document.getElementById(workflowDiv).innerHTML = 'Item emailed';
}
else{
document.getElementById(workflowDiv).innerHTML = '<div style=\"color:#FF0000\">Error</div>';
if (xData.responseXML != undefined)
window.alert(xData.responseXML.text);
else
window.alert("Error. call assistance, probably the workflow was changed and has another GUID."); }
}
});
}
When I use the Fiddler I get a 404 error when it hits the SPServices function for StartWorkflow (GetList works fine). This is what is confusing me. I know SPServices is working because it works for GetList. But the StartWorkflow function is failing.Again, any help to clear up my confusion on SPServices here would be appreciated.