Hi all,
I'm using the following JS function to call a WorkFlow from Javascript:
function TriggerWorkflow() {
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);
}
The result is that workflow does not start and looking at CRM Trace Logs it shows this error:
at SoapHeaderAuthenticationProviderBase.Authenticate(HttpApplication application)
at AuthenticationStep.Authenticate(HttpApplication application)
at AuthenticationPipeline.Authenticate(HttpApplication application)
at AuthenticationEngine.Execute(Object sender, EventArgs e)
at SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
at ApplicationStepManager.ResumeSteps(Exception error)
at HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
at HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)
at HttpRuntime.ProcessRequestNoDemand(HttpWorkerRequest wr)
at ISAPIRuntime.ProcessRequest(IntPtr ecb, Int32 iWRType)
>CrmAuthenticationToken is missing.
The WF is set as "OnDemand" and the scope is Organization. I'm logged with System Administrator user role.
Do you have any idea about the problem?
Thanks to everyone
Marco