Introduction
In my previous article, we completed the 1st module of this 2-part exercise where we loaded multiple data sources into a dropdown control. In this article, we will continue with the 2nd module and load content from the selected data source.
Collect Data based on a selected list
Similar to how we collected the list names, we will collect list data using PowerAutomate.
- Navigate here
- Click on “Create” and select “Instant flow”
- Give flow a name, like, “QuizBuzz_GetListData”. Select “PowerApps” as a trigger and click on “Create”.
- Add a New Step -> “Get Items”, and configure it with the Site URL where all quiz lists are created, for a list name, select “Ask in PowerApps” from dynamic content
- Next, initialize three String variable and name it “Questions”, “Answers” and “CorrectAnswers”
- Run the flow once, so that it generates the JSON for the “Get Items” step. We will use the JSON output in our “Parse JSON” step. For “Content”, use “value” from “Get Items” step and for “Schema”, click on “Generate from Sample” and copy the JSON output of “Get Items” step
- Next, loop through the parsed JSON and append questions, answers, and correct answers to appropriate variables. Ensure that the data is separated by a special character such as a semi-colon (;) or hash (#)
- Finally, add a step “Respond to a PowerApp or Flow”, this action will allow you to add an output. We will choose “Text”, provide an appropriate name to the response variables, and assign respective string variables to response outputs.
Note
Currently, there is no option to send an Array or Collection to PowerApps. Hence, we pass the output as String and create a collection in PowerApps after receiving data from Flow.
Loading Content in PowerApps
We have sent the data from SharePoint Lists to PowerApps using PowerAutomate. Now, we need to convert these strings into respective collections that will be used in different controls in our Quiz App.
- Navigate here
- Click on “Apps” and select the previously created app. Click on “Edit” to open the app in Edit mode.
- Add a button to the app and let’s call it “Start Quiz”. We will need to associate the flow in PowerApps. So, select the Button in the tree view, then click on "Action" -> "Power Automate". Now, select the flow that we had created earlier. This flow will also need a parameter from PowerApps, so let’s pass the selected value in lists dropdown as List Name parameter to Flow.
- In the”OnSelect” of the button, Run the Flow that was created earlier and collect the result in a variable. Since the result is in String format, we will convert it into a collection by splitting based on the special character provided
- In the same action, add one more collection, that will contain the answers for the current question
- Add a label that will hold the question for the quiz, set the “Text” property of the label as follows
- Add a Radio Buttons control, that will hold the answers for the quiz, set the “Items” property of this control as follows. “Shuffle” function allows the collection to be placed in random order.
- Now, add another button and call it “Next”. We will use this button to Remove items from collection one at a time and move through the remaining questions. In the “On Select” action of this button, set the property as follows
Final Outcome
Now, the app should be ready to test. Load some data in both of the lists in SharePoint. In the PowerApps, right-click on App -> Run OnStart, this should load the dropdown. “Play” the app and click through the quiz. You would see that the data is loaded based on the selection in the dropdown.