Power Pizza: Choosing a Winner

We are in the middle of a Power Pizza Blog Series! I am walking through lessons learned while building a Power App to track your Pizza Crawls. This will allow your friends to submit their locations, enter ratings and view the winner. Finally, a scientific solution for finding the best pizza!

Del Ray Pizza Alexandria
Del Ray Pizza empirically won our Pizza Crawl and it was amazing so I had to show it again!

Now that we are getting all the scores in, we need to be able to display the winner back to the pizza eaters. I am already showing the locations ordered by their score, so you could see the winner there but that’s not quite enough fanfare. I also wanted the winner stamped on the Pizza Party record for future reference.

Setting The Winner

I decided that I wanted to have a Power Automate Flow trigger off a button in the app to populate the winner and then navigate to the winner announcement. I created the shell of a flow to do this but kept running into this pesky error when attempting to trigger off of the button press.

Button to Flow Error
Error when calling a Power Automate Flow from a Power Apps Button

I reached out to Vivek Bavishi as he had been getting a similar error previously. He was also having the issue when the connected Power Automate Flow was using the Common Data Service (Current Environment) connector. So he suggested that I use a Flow that calls a child Flow where the work was actually done.

So I needed to have a parent Flow which would accept the GUID for the Pizza Party selected in the app. This would call the child Flow and pass that GUID. The child Flow then grabs locations associated with that party to get the one with the highest score. This is then dropped into the Pizza Party record in CDS. Let’s look at what this looks like.

Parent Power Automate Flow
Power Automate Parent Flow that takes the GUID from the Power App and pushes it to our child Flow
Power Automate Child Flow
This is part 1 of the child Flow in Power Automate. We get the Pizza Party record based on the GUID sent from the parent. Then we want to list the top 1 Pizza Location for that Party

Let’s pause for a second to talk about how I knew what to put in the advanced options above. This all came from the FetchXML Builder in the XrmToolBox! Thank you Jonas Rapp! I can create my query there and then simply copy the parameters over to Power Automate. I created my query using a sample GUID from my environment and then replaced this with our dynamic link coming from the Power App.

FetchXML Builder for Power Automate Parameters
Using FetchXML Builder to get the Power Automate List Records Parameters
Power Automate Child Flow Part 2
Here is part two of the Child Flow in Power Automate

You will notice that this looks a lot more complicated than you would expect. Initially I had just updated the record with the current item link but this was causing the below error.

Power Automate Error Input String was not in correct format
When passing the ID directly I received this error: Input string was not in a correct format

The community came to the rescue again with this blog by Antti Pajunen. This shows how to take what was received from the get records and translate it into the right format to be absorbed correctly. Note that when you build the formula in the blog, you do need to use the Expression area of the Dynamic Content pane and can’t just lazily copy.

Finally we have a step to send a response. I honestly don’t know why that needs to be there but I got an error earlier on in the process that told me to add a response. So I did.

Finally a successful run! Now just to display this in a nice way to the user!

Triggering from App

Now that the Flow works, we just need to call it from the Power App. The important piece here is making sure the data point you pass is the one that Power Automate is expecting. I also wanted this to trigger the Flow and then navigate to the other page and to do that you can put the two commands together with a semicolon (;).

You will also note the silly name of the Power Automate Flow. This is because I tried creating this multiple times and ran out of logical names. So they started being named after the time. I changed the front end name that is visible in the solution but the evidence of my multiple failures still endures.

Button to Trigger Power Automate
Calling the Parent Flow (in Power Automate) off of a Power App button and then navigating to another page to display the winner (Photo by Chad Montano on Unsplash)

I did consider that this button could be pushed before all pizzas had been tasted or pushed by multiple pizza eaters at the end of the evening. I determined this was a reasonable level of extra potential runs. It’s possible someone could want to see who was winning so far but we would still want it to recalculate at the end so we saw the real answer.

Displaying The Winner

I confirmed that the flow was correctly updating the Pizza Party records so now the last piece was to display. My plan was to have a page that would list the winning location with its total score and possibly include a gallery of the related ratings for that location. Then you could see the pizza pictures taken earlier in the party.

Unfortunately I ran into a snag whenever I attempted to get details from that Winning record. I could display the Pizza Party information and I could see there was data in that field but I couldn’t get the data from the winning record to display.

Power App Data not displaying
As you can see here the data is correctly in the records (pulling in to the data view) but not showing up in my text fields. The gray box is the current state of my gallery. It’s important to be sharing our failures as well as our successes!

I could validate that Power Automate was correctly setting the Winning Location but for some reason I couldn’t get the Power App to show that field. Additionally in my Beta Testing I found that it was not firing at the right time to be picked up in the Power App. So I decided to try and look at it another way.

Instead of pulling this data from the party record, I decided to use some galleries. So first a gallery with the top pizza location (filtered by party and only showing the top 1 record) and then another gallery for ratings filtered by this one location.

Winner Pizza Locations Filter and Select
Pizza Location gallery is only showing the first record in the list and sorted by top score. This is similar to the locations gallery (see Sticky Option Sets post). Then the default is set to this first item so that it is selected.
Winner Pizza Ratings Filtered by Gallery
Next we want the ratings to show only those ratings for that top pizza location. So we can grab the selected of the locations gallery and use that here

Voila, we have a winner announcement! Still some room for fireworks but that can go on the future enhancement list. More #PowerPizza lessons coming tomorrow!

One thought on “Power Pizza: Choosing a Winner

Leave a Reply