How to pass Power Apps Collection in Power Automate using Json Function

By | May 13, 2020

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:

Power Automate using Json Function

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})

Power Automate using Json Function

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))))

Power Automate using Json Function

4. Now let’s create a Power Automate which run on click of Power Automate using Json Function 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:

Power Automate using Json Function

5. Now add an action as ‘Parse Json’ and add content ‘Ask in PowerApps’ as shown in below screenshot:

5. Now add an action as “Parse Json” and add content as “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:

Power Automate using Json Function

7. Now back in the Power Apps on ‘On Select’ property of the  Power Automate using Json Function icon add the MS flow by selecting Action -> Power Automate ->’MS flow’:

Power Automate using Json Function

Power Automate using Json Function

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))

Power Automate using Json Function

9. Now run the app, select users, click on icon and see the collection is passed to Power Automate.

Power Automate using Json Function

10. Now as shown in below screenshot the flow has run successfully and the entire collection is passed in flow.

Power Automate using Json Function

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.

Free 70% of storage space in CRM with Attachment Management Apps!

Attach2Dynamics – Store and manage documents/attachments in cloud storage of your choice – SharePoint, Dropbox or Azure Blob Storage from within Dynamics 365 CRM.
SharePoint Security Sync – Robust and secure solution to integrate Dynamics 365 CRM and SharePoint Security Sync thereby ensuring secure access to confidential documents stored in SharePoint.