How to Call A Flow From PowerApps And Get Back The Response

Introduction

While working with PowerApps, many times we require a response from Power Automate. In this article, we will learn

  • how to call a Power Automate flow from PowerApps
  • send parameters to Power Automate from PowerApps
  • get response from Power Automate to PowerApps

To call a Power Automate from PowerApps, we will need to create an instant flow. Only instant flows (with trigger as PowerApps) can be called from PowerApps. Let’s first create an instant flow that we will call from PowerApps.

Step 1 - Create an Instant cloud flow

  • Navigate to power atomate portal and click on New Flow > Select Instant cloud flow.
    Create an Instant cloud flow
  • Enter the flow name
    Create an Instant cloud flow
  • Select the trigger as PowerApps(V2)
  • Click on create button
    Create an Instant cloud flow

In this example, we will try to calculate the difference between two dates. We will pass the dates from PowerApps to Power Automate as parameters.

Step 2 - How to pass parameters or input to flow from PowerApps

  • Click on Add an input from the PowerApps trigger as shown below:
    How to pass parameters or input to flow from PowerApps
  • Choose the type of user input:

    Here we can see that we have 6 types of inputs or parameters that can be passed to power automate. In our case, we are going to calculate the date difference, so we will use the date parameters.
    How to pass parameters or input to flow from PowerApps
  • Let’s add two date parameters for calculating the date difference as shown below
    How to pass parameters or input to flow from PowerApps
  • Now we will initialize a variable named as varDateDifference and type as integer.
  • Then to calculate the date difference, we will set the same variable will below formula
    div(sub(ticks(EndDate),ticks(StartDate)),864000000000)

    How to pass parameters or input to flow from PowerApps

Now our flow is ready to be triggered from PowerApps with parameters.

 Step 3 - How to call a Power Automate flow from PowerApps

  •  From your PowerApps application, click on Add flow option and select the flow from the list of available instant flows. Please find below screenshot:
    How to call a Power Automate flow from PowerApps
  • Now once the flow is added to your PowerApps, you can call it on different events like OnVisible,OnStart, OnSelect, etc.  Let’s call the flow on click of a button. Here I have used two date picker controls for which I need to find the date difference
  •  So write a formula on OnSelect property of the button and pass the value of parameters to the flow. 
    Callflowfrompowerappsandgetbackresponse.Run(DatePicker1.SelectedDate,DatePicker1_1.SelectedDate)

    How to call a Power Automate flow from PowerApps

In this way, we can call a power automate from PowerApps. Now let’s see how to get the response back from the power automate.

Step 4 - Get a response from Power Automate to PowerApps

To response back to PowerApps, we need to use the action called as “Respond to a PowerApps or flow”.

  • At the end of the flow, add an action as “Respond to a PowerApps or flow” and click on Add an output 
    Get a response from Power Automate to PowerApps
  • Choose the type of output
    In this case, as we want to pass the days difference, we will use the number as the output type:
    Get a response from Power Automate to PowerApps
  • Enter the title for output
    This is just the output property name that we will use in PowerApps to read the value
    Get a response from Power Automate to PowerApps
  • Get the response of flow in one variable 

    Now when the flow returns the value, we will need to store that value in one of the variable. In this case, I have used a variable named, varDateDifference which will store the response value that we have configured in above step. 
    Set(varDateDiffernce,Callflowfrompowerappsandgetbackresponse.Run(DatePicker1.SelectedDate,DatePicker1_1.SelectedDate).datediffernce)

    Get a response from Power Automate to PowerApps

  • To show the response value, we can use labels, or text inputs, etc. Here I am using the text input to show the date difference.
    Get a response from Power Automate to PowerApps

Conclusion

In this way, we have learned how to call a Power Automate flow from PowerAppss, Send parameters to Power Automate from PowerApps, get response from Power Automate to PowerApps and how to calculate date differences.


Similar Articles