Category: Power Automate

  • Power Automate: Mock action outcomes using “Static result”

    Power Automate: Mock action outcomes using “Static result”

    Note: This post was written in June 2022. Some screens and steps may have changed since then.

    Imagine this scenario:

     You are building a complex Power Automate flow, we’re talking hundreds of actions. You want to test a specific section, which for your luck (or lack of it) comes after a five-layer approval.

     Every time you want to test your section, you’re wasting at least ten minutes to complete all five layers of approval, before you can get to the section you want to test.

     And the worst part is: you don’t even care about the freaking approvals, they are already tested… all you want is for the flow to proceed to the section you want to test.

     Well… you don’t need to deal with this frustration anymore.

     In this blog post, you’ll learn how to speed up your testing, and reduce these ten minutes of wasted time per run, to zero minutes. Yep… ZERO!

     One of the most time-consuming actions to complete is the Start and wait for an approval. Simply because you must leave your flow designer, open Teams or Outlook, find your notification and complete the approval, then come back to the designer.

     So, for this blog post, I chose the Start and wait for an approval action as our example for a long running action that we can mock its outcome. However, you can use the same concept for most actions.


    So, what are you learning today?

     Today you will learn how to speed up your Power Automate flows testing, by mocking action outcomes, using the Static result action property.


    Let’s see how it works

     In the steps below we will mock the outcome of the Start and wait for an approval action.

     We will do it in two steps:

    1. Capture the action’s outcome
    2. Configure the action to return the same outcome for future flow runs, without manual intervention

    1 of 2: Capture the action’s outcome

    1. Create a new, manually triggered, flow with two actions:
      • Start and wait for an approval
      • And Compose
    Power Automate flow with a Start and wait for an approval action followed by a Compose action
    1. For Start and wait for an approval action, fill-in the fields as you please
    2. In the Compose action, put the outcome of the Start and wait for an approval action:

    outputs(‘Start_and_wait_for_an_approval’)?[‘body/outcome’]

    2 of 2: Use the Start and wait for an approval outcome for future flow runs

    1. Run the flow once, and complete the approval
    2. Now, go to your flow history and open the last run instance
    Flow run history with the completed approval run opened
    1. Expand Start and wait for an approval
    2. Click on Show row outputs
    Start and wait for an approval expanded with the Show raw outputs link highlighted
    1. Copy the body, starting with: “body”, all the way to the closing bracket: }
    Approval outputs showing the body JSON to copy
    1. Now, in the flow editor, click on the three dots on Start and wait for an approval -> Static result (Preview)
    Three-dot menu on the approval action with the Static result (Preview) option
    1. Toggle Enable Static Result (Preview)
    Enable Static Result toggle switched on
    1. Click on Switch to JSON mode
    Static result panel with the Switch to JSON mode link
    1. The static result will show up without a “body” key/value:
    Static result JSON before the body is added
    1. Add a comma after the “headers” line
    2. Then paste the body you copied in step (5) above, on a new line
    Static result JSON with the copied body pasted below the headers line
    1. The full JSON looks like the following:
    Completed static result JSON for the approval action
    1. Click Done
    2. Now run your flow
    3. It will skip running the Start and wait for an approval action, while Compose will still show the outcome that you selected in step (1) above
    Flow run where the approval is skipped and Compose shows the chosen outcome

    Few notes

    1. Notice that when we manually completed the approval action the first time, it took 26 seconds:
    Run history showing the approval action took 26 seconds
    1. While when we used the mock result, it took zero seconds
    Run history showing the mocked approval action took zero seconds
    1. The beaker icon means that the flow has used the mock result
    Beaker icon on an action showing it used the static result

    Conclusion

     Mocking action outcomes is one of the less-known features of Power Automate which can save us, developers, a lot of time.

     Even though we demonstrated the feature on the Start and wait for an approval action, the feature is available for most actions in Power Automate.

     I encourage you now to go ahead and try it on a different action.


    References

    Test workflows with mock data in Azure Logic Apps (applies to Power Automate as well): https://docs.microsoft.com/en-us/azure/logic-apps/test-logic-apps-mock-data-static-results?tabs=consumption