User Review
( votes)Introduction
Earlier, we have seen how to pass parameter from Power Apps to Power Automate. In today’s blog, we will explore how to pass the Collection from Power Apps (Canvas App) to Power Automate. A collection in Power Apps is used to store data. You can explore more about Collection in Power Apps here. Now, consider that you want to update a large amount of records using Patch and ForAll functions in background asynchronously, so user has no need to wait for completion of request. To process this we need to create Power Automate where a collection from Power Apps will be passed and the flow will process the collection and do the operation as per our requirement since if we use Patch and ForAll functions and user exits the app the operation may stop. Below we have shown an example to pass the collection from Power Apps to Power Automate.
Now let’s consider a scenario where Manager wants to send a mail to other users in system to follow up the task.
1. We created a sample user app and design as shown in below screenshot:
2. Now on ‘onCheck’ property of the Checkbox lets create a user collection with below formula:
Collect(UserColle,{userEmail:ThisItem.’Primary Email’,fullName:ThisItem.’Full Name’,userId:ThisItem.User})
3. Now on ‘onUnCheck’ property of the Checkbox lets remove the user from user collection with below formula:
If(LookUp(UserColle,userId=ThisItem.User, true ),Remove(UserColle,First(Filter(UserColle,userId=ThisItem.User))))
4. Now let’s create a Power Automate which run on click of icon and sends email to the selected users in the app. Login to https://flow.microsoft.com/ and create a new flow using the ‘Power App Button’ Template as shown in below screenshot:
5. Now add an action as ‘Parse Json’ and add content ‘Ask in PowerApps’ as shown in below screenshot:
6. Now add ‘Apply to each loop’ to send email for the each selected user as shown in below screenshot:
7. Now back in the Power Apps on ‘On Select’ property of the icon add the MS flow by selecting Action -> Power Automate ->’MS flow’:
8. As soon as the Power Automate is added on the ‘On Select’ property pass the User collection in JSON format as shown below:
SendEmail.Run(JSON(UserColle,JSONFormat.Compact))
9. Now run the app, select users, click on icon and see the collection is passed to Power Automate.
10. Now as shown in below screenshot the flow has run successfully and the entire collection is passed in flow.
You can refer more on JSON function in Power Apps here.
Conclusion
Thus, as illustrated above you can now easily pass the entire Power Apps collection in Power Automate by using JSON function.