Here is the logic to call on-demand workflow from java script.
function TriggerWorkflow() {
// pass the workflow guid
var WorkflowId ="61A3C919-9636-44DC-87E4-C5FF2A63F2B4";
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\">" +
GenerateAuthenticationHeader() +
"<soap:Body>" +
"<Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
"<Request xsi:type=\"ExecuteWorkflowRequest\">" +
"<EntityId>" + crmForm.ObjectId + "</EntityId>" +
"<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.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseXML;
return (resultXml.xml);
}
I added my workflow GUID but nothing is happening, how do I debug? I'm trying to call this from CRM on office 365!
ReplyDeleteWhat kind of error are you getting? Try debugging javascript. I tried long back, i'm not sure still this script working or not.
Delete