Cross Browser Support For Calling Workflow Via Ribbon Buttons
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
Written by neilmcd
Mar 27, 2013 at 5:17 pm
Posted in CRM 2011
Tagged with crm2011, javascript, ribbon buttons, workflows
2 Responses
Subscribe to comments with RSS.
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Not sure but why don’t you use 2011 SOAP endpoint for that as it is shown in following article – http://mileyja.blogspot.com/2011/06/execute-workflow-using-net-or-jscript.html
Andrii Butenko (@a33ik)
Mar 28, 2013 at 2:58 pm
Hey Andrii. You’re right, I should probably update it to use the 2011 endpoint. It’s just some ancient script which I needed to get working again urgently!
neilmcd
Mar 28, 2013 at 4:12 pm