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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Real Time Workflow Execution via HTML Button

(0) ShareShare
ReportReport
Posted on by 84

We use HTML Web Resource objects to create buttons that we can place on CRM forms to execute Workflows (called by the Workflow ID in the HTML).  However, even if the Workflow itself is real-time, execution via HTML button does not show the results, and users need to refresh the page manually after clicking any of these buttons.  (We've tested the workflows, they do refresh the data in real time and show the desired changes immediately upon execution when called via the Flows menu.  So the issue is not with the Workflow itself.)

For example, we have a workflow on a custom entity that sets 8 different Boolean fields to Yes for a given client.  It's a timesaver for data entry when all conditions apply to a given client.

Here is the HTML we currently use, can anyone suggest additional HTML (or other solution for a Web Resource) to have the flow execute in real time and show the results without a manual user refresh?

--------------------------------------

<html><head>
    <script type="text/javascript">
      function executeWorkflow() {

        console.log(
          "Record ID:" +
            window.parent.Xrm.Page.data.entity.getId()
        );

        var entity = {
          EntityId: window.parent.Xrm.Page.data.entity.getId() // recordId
        };


        var WorkflowId = "F5B6A605-0224-47D7-BC3F-DA187D7D4A51";
 

        var req = new XMLHttpRequest();
        req.open(
          "POST",
          window.parent.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) {
        //     window.parent.Xrm.Utility.alertDialog("Success");
          } else {
        //   window.parent.Xrm.Utility.alertDialog("Alert");
        //   }

          }
        };
        req.send(JSON.stringify(entity));
      }
    </script>
  <meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta></head>

  <body dir="LTR" onfocusout="parent.setEmailRange();" style="overflow-wrap: break-word;" lang="en-US">
    <button onclick="executeWorkflow()" type="button">
      All Eligible
    </button>
 

</body></html>

--------------------------------------------

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Add following code after lines

    if (this.readyState === 4) {

               req.onreadystatechange = null;

    var entityFormOptions = {

    entityName: parent.Xrm.Page.data.entity.getEntityName(),

    entityId: parent.Xrm.Page.data.entity.getId()

    };

    parent.Xrm.Navigation.openForm(entityFormOptions);

    this code should reload the form.

  • GBarkin Profile Picture
    84 on at

    Hi Andrew - that worked to refresh the form.  For bonus points, I need to return to a specific tab on the form upon reload.  Is there a way to have the form reload and go to a specific tab?  

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Potentially you can do that but that would require additional configuration and scripting but I haven't tried that so it's on you to check if it works or not.

    1. Create a custom parameter - docs.microsoft.com/.../configure-form-accept-custom-querystring-parameters

    2. Pass that parameter through parameters.

    3. Create onload handler to check that passed parameter and if it was passed - navigate to the proper tab.

    Good luck!

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 171 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 83

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans