Hello,
I am trying to run a specific workflow when a user loads a specific entity. I'm using a workflow to copy account balances from one entity to another, but I need the balances to update whenever a user loads the page where the data is copied to. Account balances change daily on the source entity.
I've copied code from other forums and input my one workflow and entity IDs, I get the confirm window to pop up, but the workflow doesn't run. Any suggestions on how I can get this to work?
function RunWorkflow() {
var _return = window.confirm('Do you want to update the data?');
if (_return) {
var url = Xrm.Page.context.getServerUrl();
var entityId = '8AF4749E-41AE-E911-9136-00505694692C';
var workflowid = '97BED1B8-5D32-40D7-9EB2-BE5996E35F0A';
var OrgServicePath = "/XRMServices/2011/Organization.svc/web";
url = url + OrgServicePath;
var request;
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/.../\">" + entityId + "</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, 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", "">schemas.microsoft.com/.../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');
}
}
}
Thank you!