How to return value(s) from Microsoft Flow to PowerApps

One of the new feature available in Flow & PowerApps is that Flow can easily return value(s) to PowerApps. This is very important because we can now easily use Flow as a business layer for PowerApps.

I’ve created 2 very basic demonstrations in order to evaluate this new feature :

Demo 1. Basic PowerApps calculator : and of course the calculation happens in Microsoft Flow

Create the following PowerApps application:

powerappsflow1

 

  • Save the PowerApps as MyPowerAppsFlowCalculator.
  • Go to Microsoft Flow and create a new Flow from scratch; name it FlowCalculator.
  • The flow trigger must be PowerApps.
  • Define 2 variables A and B (of type float):powerappsflow2
  • Add a last action of type PowerApps – Respond to PowerApps
  • In this action, define and an output value with the following expression :powerappsflow3
  • Go back to variable A definition; click on value, and in the dynamic content click on  Ask in PowerApps :powerappsflow4
  • a PowerApp Initalization  variable will be created and associated to variable A.
  • Follow the same procedure for variable B as well.
  • Save the flow.
  • Go back to your PowerApps, select the Calculate button and add a Flow action : choose the FlowCalculation flow :

powerappsflow5

When doing this, code for calling the flow will be generated and associated with the OnSelect event. You can complete this code by passing your fields value :

powerappsflow7

That would work, but we still need to retrieve the flow value; so let’s create a context variable Result and store the flow returned value in it :

powerappsflow8

And of course we need to display the calculated value in the form (here in the label ResultValueC). Select the lablel ResultValueC  and associate the Text value with Result.C  (Result is our context variable, and .C is used to grab the value from the record return by Flow.

powerappsflow9

You can now test your PowerApps (don’t forget to save it before).

 

Demo 2 : returning a set of values

I have an existing SharePoint list with a list of cities and I want to create a Flow that will return the list of cities to a PowerApps application. Each city is associated with a travel expenses. I know I know :- )  this is a little bit ridiculous because I can directly use the SharePoint connector from PowerApps, but this is a just a test : I will come up with more complex & business scenarios later.

powerappsflow10

 

Create the Flow ; I’ve named it ReturnExpensesToPowerApps.

The flow looks like this :

powerappsflow11

The Getitems action just retrieve the list values (including the Title column from the SharePoint list). More details of the other actions :

powerappsflow12

(you will notice the “,” just before Title.

…and the last one:

powerappsflow13

So basically, this flow returns an array of cities where the separator is “,”.  ( I’ve previously created a JSON array, but each city was surrounded by a double quote and I couldn’t get rid of this double quote that showed up in the PowerApps form)

Now let’s go to Powerapps and create a Form from scratch that looks like this (a Button and a listbox) :

powerappsflow14

Here is the code behind the button: I create a context variable “allexpenses” that will store the list of cities

powerappsflow16

and is is the code behind the ListBox : I generate an array from this list of cities :

powerappsflow16

…and that works :

powerappsflow17

I’m working on more complex scenarios : stay tuned !

Leave a comment