Asked by:
on demand workflow javascript crm 2013

Question
-
Hi
I am struggling to make the on-demand workflow working in JavaScript in CRM 2013. Can you please help ?
it was working fine in CRM 2011.
Thanks for your help.
Friday, April 17, 2015 8:03 PM
All replies
-
Hi Emerson,
Can you share the JavaScript code you are using to trigger the workflow? The message "ExecuteWorkflowRequest" to invoke such operation hasn't changed, have a look at this SDK article:
https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.executeworkflowrequest.aspx
Please let me know if I'm missing something or what you are trying to do is actually different.
Regards
Saturday, April 18, 2015 9:01 AM -
Hi,
There is no change. However here is the code snippet
function RunWorkflow() { var _return = window.confirm('Are you want to execute workflow.'); if (_return) { var url = Xrm.Page.context.getServerUrl(); var entityId = Xrm.Page.data.entity.getId(); var workflowId = '541B45C9-3F88-4448-9690-2D4A365C3172'; var OrgServicePath = "/XRMServices/2011/Organization.svc/web"; url = url + OrgServicePath; var request; request = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<s:Body>" + "<Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">" + "<request i:type=\"b:ExecuteWorkflowRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">" + "<a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">" + "<a:KeyValuePairOfstringanyType>" + "<c:key>EntityId</c:key>" + "<c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">" + entityId + "</c:value>" + "</a:KeyValuePairOfstringanyType>" + "<a:KeyValuePairOfstringanyType>" + "<c:key>WorkflowId</c:key>" + "<c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">" + workflowId + "</c:value>" + "</a:KeyValuePairOfstringanyType>" + "</a:Parameters>" + "<a:RequestId i:nil=\"true\" />" + "<a:RequestName>ExecuteWorkflow</a:RequestName>" + "</request>" + "</Execute>" + "</s:Body>" + "</s:Envelope>"; var req = new XMLHttpRequest(); req.open("POST", url, true) // Responses will return XML. It isn't possible to return JSON. req.setRequestHeader("Accept", "application/xml, text/xml, */*"); req.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute"); req.onreadystatechange = function () { assignResponse(req); }; req.send(request); } } function assignResponse(req) { if (req.readyState == 4) { if (req.status == 200) { alert('successfully executed the workflow'); } } }
Relevant links:
http://www.mscrmconsultant.com/2013/03/execute-workflow-using-javascript-in.html
https://community.dynamics.com/crm/f/117/t/143712.aspx
Hope this helps.
-----------------------------------------------------------------------
Minal Dahiya
blog : http://minaldahiya.blogspot.com.au/If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"
Sunday, April 19, 2015 10:37 AM