User Review
( votes)In this blog, we learn about filtering JSON arrays in Power Automate. We all know that this type of requirement can easily be solved using JavaScript. But in this method, we have to create a web resource to register the script in CRM. Now, we can achieve this requirement within the CRM process itself. Power Automate introduced the Filter Array action, using which we can easily filter the JSON array of objects and get the exact output from the JSON array.
Problem:
We have JSON data containing individual Employee’s Project Details, which specify that a single employee is working on how many projects, he completed how many projects, the estimation of the projects in days, and when those projects get started. Please find the below JSON array that we want to filter:
{ { "Project Name": "Employee Payroll System", "Start Date": "22-05-2021", "Duration": 65, "Industry": "IT Corporate", "Status": "Complete" }, { "Project Name": "Healthcare Solution", "Start Date": "22-03-2023", "Duration": 95, "Industry": "Heath and Hospitality", "Status": "In Progress" }, { "Project Name": "Pharmacare Solution", "Start Date": "26-03-2022", "Duration": 32, "Industry": "Heath and Hospitality", "Status": "Complete" }, { "Project Name": "Agro Management System", "Start Date": "22-08-2021", "Duration": 120, "Industry": "Agriculture", "Status": "Complete" }, { "Project Name": "Finance Management System", "Start Date": "22-08-2023", "Duration": 38, "Industry": "Finance", "Status": "Not Started" } }
In the below JSON array, they mention five project details, so now we want to identify how many projects an individual employee has completed for a duration greater than 40.
Solution:
To resolve this problem, we go with the Power Automate solution. We have created an on-demand Power Automate flow. In that we have passed the above JSON array to the flow as input as shown in the below screenshot:
After that, we apply the Filter Array action on the above input of JSON array as shown below in the screenshot:
Please find the below Filter Array expression that we have used to get the exact output:
@and(equals(item().Status,’Complete’),greater(item().Duration,40))
In the above expression, we have applied both conditions which we have merged with the @and clause. In that,
1. The projects which were completed, were obtained using the @equals clause
equals(item().Status,’Complete’)
2. The projects which have not been completed within 40 days, were obtained using the @greater
greater(item().Duration,40)
After applying the Filter Array action we got the exact output as shown in the screenshot below:
Conclusion
Filter Array is the best option to filter the JSON array in Power Automate without writing any external programming logic.
The post How to filter JSON array using Filter Array action in Power Automate first appeared on Microsoft Dynamics 365 CRM Tips and Tricks.