Power Apps ParseJSON Function: Get Collection From A Flow
Power Apps ParseJSON Function: Get Collection From A Flow Posted by - Matthew Devaney on - October 9, 2022 74 Comments Power Apps new ParseJSON function can ...
- Published
- Reading time
- 5 min read
Before you start
Is this guide for you?
- Best entry point
- Power Apps
- Time investment
- 5 min read
Imported reference from Matthew Devaney's blog for learning purposes. Original: https://www.matthewdevaney.com/power-apps-parsejson-function-get-collection-from-a-flow/. Author: Matthew Devaney.
Power Apps ParseJSON Function: Get Collection From A Flow Posted by - Matthew Devaney on - October 9, 2022 74 Comments
Power Apps new ParseJSON function can turn a text string into a record or table. It is especially useful when app is used to trigger a Power Automate flow and returns a value to the app.
Power Automate only allows returning a text string with the Respond To Power Apps (V2) action . But with the ParseJSON function we can easily convert that text string to another data type. In this article I will show you how to return a collection from a flow to Power Apps using ParseJSON. Table of Contents Setup The SharePoint List Create A Flow In Power Automate Send The Flow Result To Power Apps “>Determine The Flow Output JSON Schema
Use The ParseJSON Function To Create A Collection Display The Collection In A Gallery
Introduction: The Car Sales Inventory App
The Car Sales Inventory app is used by salespeople at a car dealership to create a report on all the cars currently in-stock. They open the app to the inventory screen and click on a button to show all cars in a SharePoint list. Setup The SharePoint List
Create a new SharePoint list called Car Inventory with the following columns: Year (number) Make (single-line text) Model (single-line text) PurchaseDate (date only) Sold (yes/no)
Load this sample data into the the SharePoint list: CarYear CarMake CarModel PurchaseDate Sold 2009 Mazda MX-5 10/21/2020 Yes 1985 Honda Accord 5/2/2018 Yes 2001 Ford Windstar 10/22/2019 Yes 1994 Mitsubishi Eclipse 2/16/2019 No 2003 Lamborghini Gallardo 11/9/2020 Yes 2005 Subaru Legacy 11/3/2020 Yes 1997 Ford Explorer 6/15/2018 Yes 2010 Lexus GS 6/11/2019 Yes 2010 Dodge Ram 9/7/2020 No 1995 Volvo 960 8/22/2018 Yes Create A Flow In Power Automate
Open Power Apps Studio and create a new blank canvas app. Insert a rectangle shape at the top of the app to make a header. Place a label on top of the rectangle to show the app’s title.
Browse to the Power Automate tab on the left-navigation menu. Then select Create new flow.
On the Create your flow menu choose + Create from blank .
Name the flow Get Car Inventory SP List Items . Send The Flow Result To Power Apps
Next we will retrieve items from the Car Inventory SharePoint list in Power Automate and send the result the result back to Power Apps. Add the SharePoint – Get Items action to the flow as shown below.
The SharePoint Get Items action only returns up to 100 records by default. To increase the limit go the action’s settings menu, turn on pagination, and write a number in the threshold field. The maximum value is 5000.
There are several columns in the SharePoint list we don’t want to bring into Power Apps (modified by, modified on, id, title, etc.). Use the Data Operations – Select action to show the columns we want and drop the other columns we don’t need.
Finally, put a Power Apps – Respond to a PowerApp or flow action at the end of the flow. Add a text type output called Result .
Use this flow expression to return the array of values created in the previous Select action to Power Apps.
outputs( 'Select:_Car_Inventory_Columns' ) Code language: JavaScript ( javascript ) Determine The Flow Output JSON Schema
To use the ParseJSON function in Power Apps we must determine the JSON schema output by the flow. The best way to do this is by running a test of the flow and inspecting the final flow action. Go to the maker portal, browse to the flows tab and open the Get Car Inventory SP List Items flow.
Click on the Test button and run a manual test of the flow.
After the flow test is finished, look at the outputs of the Respond to a PowerApp or flow action. The body property contains the JSON schema. Notice that the SharePoint items are contained inside the body property of a JSON object. This information will come in handy soon when using the ParseJSON function in Power Apps.
Use The ParseJSON Function To Create A Collection
When a button is pressed in Power Apps we want to load the flow output into a collection. Insert a new button and place it on the screen.
Use this code in the OnSelect property of the button. It runs the Power Automate flow and converts its output in the result property (text data type) into an untyped object using ParseJSON. Then it uses ForAll to loop over the untyped object and define each column’s data type using the Value function , Text function , Boolean function and DateValue function . These functions are known as type constructors .
Also, notice that we used the body property of the ParseJSON function result. This is why we needed to determine the flow output’s JSON schema in a prior step. ClearCollect ( colCarInventory , ForAll (
Table ( ParseJSON ( GetCarInventorySPListItems .Run () .result ) .body ), {
Year : Value (Value.Year), Make: Text (Value.Make), Model: Text (Value.Model), Sold: Boolean (Value.Sold),
'Purchase Date' : DateValue (Value. 'Purchase Date' ) } ) ) Code language: CSS ( css ) Display The Collection In A Gallery
We’re almost done. The last step is to display the collection in a gallery. Add a new gallery to the screen and use the collection colCarInventory as the datasource.
Insert 5 labels into the gallery: 1 label for each column in colCarInventory .
Then write of line this code block in each label to display the field’s value in the gallery. ThisItem .Year ThisItem .Make ThisItem .Model ThisItem .PurchaseDate ThisItem .Sold Code language: CSS ( css )
Finally, create one additional label and place it on top of the gallery. Write the matching column names into the label. The app is now finished. Did You Enjoy This Article? 😺
Subscribe to get new Copilot Studio articles sent to your inbox each week for FREE Enter your email address Sign Me Up Questions?
If you have any questions about Power Apps ParseJSON Function: Get Collection From A Flow please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion. Matthew Devaney M365 Copilot Power Apps
How To Create Copilot Custom UI Widgets In Power Apps
Tagged
Collections · Power Apps
Have a Microsoft 365 topic idea?
Share article suggestions, community session ideas, corrections, or real-world scenarios for future nextM365 learning notes.
Keep learning Microsoft 365
Explore more practical guides for SharePoint, Power Platform, Copilot Studio, migration, automation, governance, and security.
Continue learning
Related tutorials
Related questions
Related comparisons
Next action