Filtering an array in Microsoft Flow.

 Hello Guys,

In our previous blog we have seen how to create an array in MS Flow. Today we are going to learn how to use filter array data operation in Microsoft Flow. If you are new to MS Flow then please read my this blog.



Do follow us to know more about Dynamics and Power Platform. Also if you like our blog then please comment and share this blog with your friends.

We will be working with same flow which we have created in previous blog.




As you can see in above image we have already created one flow in which we have created one Employee Array and it contains some sample data as below.

[
  {
    "ID""c4270d27-5bfe-ea11-a815-000d3a5306e5",
    "First Name""Ravish",
    "Last Name""Gupta",
    "Address""French Quarter",
    "City""New Orleans",
    "Department""IT",
    "Salary"56000
  },
  {
    "ID""6774d9a8-5bfe-ea11-a815-000d3a5306e5",
    "First Name""Anupriya",
    "Last Name""Gupta",
    "Address""Hajratganj",
    "City""Lucknow",
    "Department""HR",
    "Salary"45000
  },
  {
    "ID""249cc5c1-5bfe-ea11-a815-000d3a5306e5",
    "First Name""Malishka",
    "Last Name""Rathore",
    "Address""Rajouri Garden",
    "City""New Delhi",
    "Department""IT",
    "Salary"45000
  },
  {
    "ID""bd8b1fea-5bfe-ea11-a815-000d3a5306e5",
    "First Name""Vihan",
    "Last Name""Ranjan",
    "Address""Kothrud",
    "City""Pune",
    "Department""Sales",
    "Salary"34000
  },
  {
    "ID""2153022c-5cfe-ea11-a815-000d3a5306e5",
    "First Name""Vinita",
    "Last Name""Gupta",
    "Address""Nanakwada",
    "City""New Delhi",
    "Department""Sales",
    "Salary"40000
  },
  {
    "ID""7eabb85b-5cfe-ea11-a815-000d3a5306e5",
    "First Name""Elbin",
    "Last Name""Thomas",
    "Address""Bavdhan",
    "City""Pune",
    "Department""Marketing",
    "Salary"29000
  },
  {
    "ID""145414a6-80fe-ea11-a815-000d3a5306e5",
    "First Name""Joseph",
    "Last Name""Morgan",
    "Address""St. Peter Way",
    "City""Manhatan",
    "Department""Marketing",
    "Salary"35000
  },
  {
    "ID""3ad1b1e9-80fe-ea11-a815-000d3a5306e5",
    "First Name""Wolfgang",
    "Last Name""Bogdanow",
    "Address""New Taxas",
    "City""Taxas",
    "Department""IT",
    "Salary"67000
  },
  {
    "ID""bb6a7233-81fe-ea11-a815-000d3a5306e5",
    "First Name""Nomi",
    "Last Name""Marks",
    "Address""St. Louis",
    "City""Manhatan",
    "Department""Sales",
    "Salary"43000
  }
]

So now will be filtering this array with some criteria. So first of all we will be adding a new step. Click on add a new step and search Filter Array Data Operation.

1. Filter array where Employee Name is Ravish Gupta. To achieve this configure the step as below.




You can click on Edit in advance mode and can write the criteria. For Example,

@equals(item()['First Name'], 'Ravish')

Add a new step and search Compose and configure it as below.




Here we have used Compose Data operation. As name suggest this data operation is used to create container which contains output from the previous step and you can use this output in further step.

If you have a single value that you want to re-use many different times throughout your flow and you don't want to change this value through out the execution then you can use Compose. Basically we can also use a variable(eg. Array) to store this output which is returned from Filter Array but as we know that we can change the value of the variable in any step of the flow. 

Compose is like using constant variable in any programming languages where its  value remain same through out the program and can't be change. 

Now run the flow and check the output.




As you can see in compose step(Filtered Employee) we have only one record. 

2. Filter Array where Salary is greater than 30000. Configure the Filter Array step as below




@greater(item()['Salary'], 30000)

3. Now we will be searching the Employee who are from Pune, Lucknow and New Orleans city.




@contains(createArray('Pune', 'Lucknow', 'New Orleans'), item()?['City'])

Run the flow and check the output.


















[
  {
    "ID""c4270d27-5bfe-ea11-a815-000d3a5306e5",
    "First Name""Ravish",
    "Last Name""Gupta",
    "Address""French Quarter",
    "City""New Orleans",
    "Department""IT",
    "Salary"56000
  },
  {
    "ID""6774d9a8-5bfe-ea11-a815-000d3a5306e5",
    "First Name""Anupriya",
    "Last Name""Gupta",
    "Address""Hajratganj",
    "City""Lucknow",
    "Department""HR",
    "Salary"45000
  },
  {
    "ID""bd8b1fea-5bfe-ea11-a815-000d3a5306e5",
    "First Name""Vihan",
    "Last Name""Ranjan",
    "Address""Kothrud",
    "City""Pune",
    "Department""Sales",
    "Salary"34000
  },
  {
    "ID""7eabb85b-5cfe-ea11-a815-000d3a5306e5",
    "First Name""Elbin",
    "Last Name""Thomas",
    "Address""Bavdhan",
    "City""Pune",
    "Department""Marketing",
    "Salary"29000
  }
]

In our upcoming blogs we will see some functions of an array.

Hope it helps...

Comments

Popular posts from this blog

Read Only Sub Grid & Editable Sub grid in Dynamics 365

Using Pipelines in Power platform for deploying solutions to environments.

Understanding Sales Process in D365.