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!

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.

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.


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.


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.

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.

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.

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.


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”