web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to run asynchronous workflow through Javascript and get its status whether that workflow succeded or Failed?

(0) ShareShare
ReportReport
Posted on by 106

Hello All,

I am using the code below  to run asynchronous workflow , it runs the workflow but always give success even if the workflow failed due to errors.I want to get that status whether they are succedded or failed and I have tried making true to false in the below code but still not working.Can anyone help me what should i do please or should i follow another method please let me know asap. It is urgent?

var entity = {
"EntityId": reportingRecords[j].id
};
var WorkflowId = "A86494D4-63E8-4A32-B2BB-B0D0EAB26652";
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/workflows(" + WorkflowId + ")/Microsoft.Dynamics.CRM.ExecuteWorkflow", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
console.log("Success");
} else {
Xrm.Utility.alertDialog(this.statusText);
console.log("Failed");
}
}
};
req.send(JSON.stringify(entity));

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at

    Hello,

    Why not run the workflow synchronously? Blocking a form based on an async workflow execution might not be the best user experience.

    In theory, you'd need to have the ID of the system job and query periodically the asyncoperation table and check the state and status for the workflow that is being executed.

    However as i mentioned previously, i would recommend synchronous workflows when you have real time logic built on top of the result.

  • Raghav Chadha Profile Picture
    106 on at

    For Synchronous that is real time it will block my current screen that's why not using that.

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    Instead of checking the status of the workflow, why don't you set some field of the entity within that workflow and using javascript check that field values in a set interval? So every few seconds check that field value, if it is there that means the workflow is executed successfully.

    If you still want to check for workflow status then go for Radu's suggestion of querying the system job for that workflow for that record as regarding.

    Hope this helps

  • Radu Chiribelea Profile Picture
    6,667 on at

    On the other hand you can't predict when the async workflow will be executed so i am not sure if this will bring the desired outcome.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans