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 74

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>

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

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Real Time Workflow Execution via HTML Button

    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!

  • GBarkin Profile Picture
    GBarkin 74 on at
    RE: Real Time Workflow Execution via HTML Button

    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
    a33ik 84,325 Most Valuable Professional on at
    RE: Real Time Workflow Execution via HTML Button

    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.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans