Hi, when executing workflow through javascript, is there a way to get a return value when it is done, otherwise, users get confused.
*This post is locked for comments
Hi, when executing workflow through javascript, is there a way to get a return value when it is done, otherwise, users get confused.
*This post is locked for comments
Hi sdnd,
Check this post, To execute workflow using Java-script......
https://crmhub.blogspot.in/2018/04/execute-workflow-using-java-script-MS-Dynamic-CRM.html
function executeWorkflow(accountId, workflowId, clientUrl) {
var functionName = "executeWorkflow >>";
var query = "";
try {
//Define the query to execute the action
query = "workflows(" + workflowId.replace("}", "").replace("{", "") + ")/Microsoft.Dynamics.CRM.ExecuteWorkflow";
var data = {
"EntityId": accountId
};
//Create request
// request url
//org.crm.dynamics.com/.../workflows(“f0ca33cc-23fd-496f-80e1-693873a951ca”)/Microsoft.Dynamics.CRM.ExecuteWorkflow
var req = new XMLHttpRequest();
req.open("POST", clientUrl + "/api/data/v8.2/" + query, true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
req.onreadystatechange = null;
if (this.status == 200) {
//success callback this returns null since no return value available.
var result = JSON.parse(this.response);
} else {
//error callback
var error = JSON.parse(this.response).error;
}
}
};
req.send(JSON.stringify(data));
} catch (e) {
throwError(functionName, e);
}
}
Hi Andrii ,
you are right but ... maybe it will be useful although it is not webapi; waiting for news from sdnd2000.
If you found the answer helpful, please mark as Verified
Join my network on LinkedIn Follow me on Twitter
Thank You & Best Regards
Francesco Picchi
Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY
Independent Contractor
Francesco,
It doesn't look like WebApi. Looks like Soap for me.
Hi sdnd2000,
use these two simple functions:
function RunCrmWorkflow(workflowid, entityid, name) { var runconfirm = window.confirm('Do you want to start "' + name + ' workflow"?'); if (runconfirm) { var url = Xrm.Page.context.getServerUrl(); var OrgServicePath = "/XRMServices/2011/Organization.svc/web"; url = url + OrgServicePath; var request; request = "<s:Envelope xmlns:s=\"schemas.xmlsoap.org/.../envelope\">" + "<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/.../Serialization\">" + entityid + "</c:value>" + "</a:KeyValuePairOfstringanyType>" + "<a:KeyValuePairOfstringanyType>" + "<c:key>WorkflowId</c:key>" + "<c:value i:type=\"d:guid\" xmlns:d=\"schemas.microsoft.com/.../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); 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 () { RunCrmWorkflowAssignResponse(req); }; req.send(request); } } function RunCrmWorkflowAssignResponse(req) { if (req.readyState == 4) { if (req.status == 200) { alert('Success.'); } else { alert('Waiting...'); } } }
Please let me know if you solve.
If you found the answer helpful, please mark as Verified
Join my network on LinkedIn Follow me on Twitter
Thank You & Best Regards
Francesco Picchi
Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY
Independent Contractor
When it is sync then you just have to wait till operation is executed.
When it's async I used approach similar to following - mscrm4ever.blogspot.com/.../crm-40-running-on-demand-workflow-from.html
it is sync, how to do it with async?
Hello,
Is your workflow sync or async?
André Arnaud de Cal...
292,516
Super User 2025 Season 1
Martin Dráb
231,375
Most Valuable Professional
nmaenpaa
101,156