Intermediate | Flow of the Week: Halloween Costume Decisions Made Easy With Flow

What's Up Flow Fans?   Happy Halloween!  

This weeks Flow of the week is written by April Dunnam. April is owner and lead consultant at ThriveFast, a Microsoft Partner focusing on building business solutions with SharePoint, PowerApps and Flow. She is an active blogger and speaker, blogging under the name SharePoint Siren. Check out her YouTube Channel and follow her on Twitter HERE. Also, be sure to leave some questions or comments below and she will be happy to answer them!

The Goal:

It's Halloween and you still haven't picked out a Halloween costume.  We want to find a way to make Flow do the work and pick out a Halloween costume for us!

Requirements:

  1. A Flow subscription
  2. A SharePoint list that contains a variety of possible costume options
  3. A PowerApps subscription (optional) – For this article, I decided to create a PowerApp to kick off the Flow and return the costume.  This isn't a requirement though as you could accomplish the same result with just a Flow button if you wanted to.

Setting up the Costume Database

The first step is to set up and configure the SharePoint list.  You'll want to create a new SharePoint list called Costumes using the Custom list template.  In addition to the already included Title column add three other columns Single Line of Text Columns:  Gender, Category, Image.  Populate the list with some of your favorite Halloween costumes and tag what Gender and Category it falls under (Superhero, Time Period, Horror, etc).  You can also include an Image of the costume so we can see that in PowerApps.  

Creating the Flow

In Flow, create a Blank Flow and rename it to HalloweenHelper.

For your Trigger, Select PowerApps.  If you don't want to use PowerApps then use Flow Button as your Trigger.

To retreive a random costume, we need to add a "SharePoint – Get List Items" Action.  We will point this action to the site where we created our Costumes list.  In the Filter Query of the Get List Items Action we will input the following formula so that we only return costumes that fit the selected gender and category:

Now that we have a list of the costumes that meet our requirements we need to get that down to one randomly selected item.  To do that, we will add a "Compose" action.  In the input for the compose action, we will utilize Flow's rand function which let's us get a random item.  The formula will look like this:

body('GetCostumes')?['value'][rand(0,length(body('GetCostumes')?['value']))]

Now that we have a random item, we need to pass that item back to our PowerApp.  To do that, add a "Respond to PowerApps" action.  If you are using a Flow button instead of a PowerApp then you would insert a "Notify" action.  

In the Repond to PowerApps action, add two inputs:  SelectedCostume and SelectedImage.  

Set the value of the SelectedCostume output to the following expression:  outputs('GetRandom')['Title']

Set the value of the SelectedImage output to this expression: outputs('GetRandom')['Column4']

Rename your Flow and Save.

The PowerApp

For the PowerApp side of things, create a blank phone layout app.  On the landing page, insert two buttons that allow you to select the gender for the costume.  On click of each of those buttons,  use the Set function to set a variable which holds the selected gender. 

The next screen is a gallery of all of the categories to choose from.  Once a categoy is selected, we want that to call and execute the Flow to get a random costume. If you want to call a Flow from PowerApps, click on the OnSelect property of the button that you want to use to execute the Flow.  Select the "Action" bar in the ribbon then select "Flows".  A list of all the Flow's with PowerApps as a trigger will show up on the right hand side.  Select the Flow you just created and pass in the gender and category options.  

The last screen is the one that shows you the result.  We will just need to insert an image control and a label.  Set the Image property of the image control to varResult.selectedimage and set the Text property of the label to varResult.SelectedCostume.  

Conclusion

To see how it all comes together in action, check out the video below: