Hi Ahmet,
This is the library I am using for calling the workflow.
Process.callWorkflow = function (workflowId, recordId, successCallback, errorCallback, url) {
debugger;
if (url == null) {
url = Xrm.Page.context.getClientUrl();
}
var request = "<s:Envelope xmlns:s='schemas.xmlsoap.org/.../&;>" +
"<s:Body>" +
"<Execute xmlns='schemas.microsoft.com/.../Services&; xmlns:i='www.w3.org/.../XMLSchema-instance&;>" +
"<request i:type='b:ExecuteWorkflowRequest' xmlns:a='schemas.microsoft.com/.../Contracts&; xmlns:b='schemas.microsoft.com/.../Contracts&;>" +
"<a:Parameters xmlns:c='schemas.datacontract.org/.../System.Collections.Generic&;>" +
"<a:KeyValuePairOfstringanyType>" +
"<c:key>EntityId</c:key>" +
"<c:value i:type='d:guid' xmlns:d='schemas.microsoft.com/.../&;>" + recordId + "</c:value>" +
"</a:KeyValuePairOfstringanyType>" +
"<a:KeyValuePairOfstringanyType>" +
"<c:key>WorkflowId</c:key>" +
"<c:value i:type='d:guid' xmlns:d='schemas.microsoft.com/.../&;>" + 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 + "/XRMServices/2011/Organization.svc/web", true);
req.setRequestHeader("Accept", "application/xml, text/xml, */*");
req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
req.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Execute");
req.onreadystatechange = function () {
if (req.readyState == 4) {
if (req.status == 200) {
if (successCallback) {
successCallback();
}
}
else {
if (errorCallback) {
errorCallback();
}
}
}
};
req.send(request);
}
Finally, I am getting the workflow Id from CRM and calling the workflow.
"/api/data/v8.2/workflows?$select=workflowid&$filter=name eq 'Test Workflow'
var workflowId = workflow[0].workflowid;
var recordId = Xrm.Page.data.entity.getId();
Process.callWorkflow(workflowId, recordId, SuccessCallBack, ErrorCallBack);