Quantcast
Channel: Neil McDonald's Dynamics CRM Blog » workflows
Viewing all articles
Browse latest Browse all 2

Cross Browser Support For Calling Workflow Via Ribbon Buttons

$
0
0

For some time now, I’ve been using ribbon buttons to call various workflows, both from open records and subgrids. There’s a good guide here on how to do this, but like most guides, they were written before update rollup 12 was released. Since cross-browser support was introduced in UR12, I’ve found that the ribbon buttons do not work unless I’m using Internet Explorer.

After looking at the JavaScript code again, I could see why it was failing (snippet below)

var xml = "<?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\">" +
Xrm.Page.context.getAuthenticationHeader() +
"<soap:Body>" +
"<Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
"<Request xsi:type=\"ExecuteWorkflowRequest\">" +
"<EntityId>" + guid + "</EntityId>" + //entity record ID
"<WorkflowId>" + workflowId + "</WorkflowId>" + //WorkflowId - guid of the workflow
"</Request>" +
"</Execute>" +
"</soap:Body>" +
"</soap:Envelope>";

var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Execute");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.send(xml);

The XMLHttpRequest is being created using ActiveX, which is only supported by Internet Explorer.

Simply changing the affected code to the below has fixed the issue and it now works across all browsers.

var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.open("POST", "/mscrmservices/2007/CrmService.asmx", false);

Note: The change on the second line may not be obvious, but .open has been changed to use a lower case O



Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images