cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Moshema
Frequent Visitor

Filter array can't get results

Hi,
I have an array and I want to filter it.
But no matter what in the filter I receive a null answer [].

The array is coming inside a response from an API call with the following data.
I want to go to the services array inside the response and filter it.
I have tried to put the filter inside a variable or inside a compose action but I get [] all the time.

 

Filter array step request:

Moshema_1-1670310357780.png

 


Response:

Moshema_0-1670310324147.png

 


HTTP response (source of the array I want to filter):

{
  "id"282,
  "no""1000157",
  "type": {
    "id"3,
    "name""Large Business"
  },
  "status": {
    "id"3,
    "name""Active"
  },
  "packages": [
    {
      "id"623,
      "productId"21,
      "productType": {
        "id"20,
        "name""ServicePackage"
      },
      "name""US 125 CAP",
      "startDate""2022-11-20T01:00:00+01:00",
      "services": [
        {
          "id"4746,
          "productId"30,
          "type": {
            "id"1,
            "name""Equipment"
          },
          "serviceType": {
            "id"17,
            "name""EntityService"
          },
          "startDate""2022-11-20T01:00:00+01:00",
          "name""USA DID Provisioning",
          "productReference"1294
        },
        {
          "id"4747,
          "productId"31,
          "type": {
            "id"10,
            "name""Rate Plan"
          },
          "serviceType": {
            "id"17,
            "name""EntityService"
          },
          "startDate""2022-11-20T01:00:00+01:00",
          "name""International Outbound Rate Plan",
          "productReference"1317,
          "reference""29"
        },
        {
          "id"4748,
          "productId"32,
          "type": {
            "id"10,
            "name""Rate Plan"
          },
          "serviceType": {
            "id"17,
            "name""EntityService"
          },
          "startDate""2022-11-20T01:00:00+01:00",
          "name""Over Bundle Domestic Fixed/mobile destinations Outbound calls",
          "productReference"1316,
          "reference""28"
        },
        {
          "id"4749,
          "productId"33,
          "type": {
            "id"10,
            "name""Rate Plan"
          },
          "serviceType": {
            "id"17,
            "name""EntityService"
          },
          "startDate""2022-11-20T01:00:00+01:00",
          "name""US 125 Minute Common Area Phone (CAP) Bundle",
          "productReference"1311,
          "reference""23"
        },
        {
          "id"4750,
          "productId"34,
          "type": {
            "id"10,
            "name""Rate Plan"
          },
          "serviceType": {
            "id"17,
            "name""EntityService"
          },
          "startDate""2022-11-20T01:00:00+01:00",
          "name""Paid Inbound Rate Plan",
          "productReference"1310,
          "reference""22"
        },
        {
          "id"4751,
          "productId"35,
          "type": {
            "id"3,
            "name""Recurrent Service"
          },
          "serviceType": {
            "id"17,
            "name""EntityService"
          },
          "startDate""2022-11-20T01:00:00+01:00",
          "price"0.8,
          "currency": {
            "id"1,
            "name""Dollar"
          },
          "defaultPrice"0.80000001,
          "ratePeriod""Month",
          "name""IPF-B125-CAP",
          "productReference"1295
        },
        {
          "id"4752,
          "productId"36,
          "type": {
            "id"3,
            "name""Recurrent Service"
          },
          "serviceType": {
            "id"17,
            "name""EntityService"
          },
          "startDate""2022-11-20T01:00:00+01:00",
          "price"0.4,
          "currency": {
            "id"1,
            "name""Dollar"
          },
          "defaultPrice"0.40000001,
          "ratePeriod""Month",
          "name""Monthly e911 Fees",
          "productReference"1302
        },
        {
          "id"4753,
          "productId"37,
          "type": {
            "id"3,
            "name""Recurrent Service"
          },
          "serviceType": {
            "id"17,
            "name""EntityService"
          },
          "startDate""2022-11-20T01:00:00+01:00",
          "price"0,
          "currency": {
            "id"1,
            "name""Dollar"
          },
          "ratePeriod""Month",
          "name""Monthly DID fee",
          "productReference"1303
        }
      ],
      "productReference"21
    }
  ],
  "startDate""2022-11-20T01:00:00+01:00",
  "language": {
    "id"1,
    "name""English"
  },
  "precision"2
}


If anyone can help I'll be very grateful, thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Sundeep_Malik
Community Champion
Community Champion

Hey @Moshema 

 

Not perfectly sure, but don't match array to an array, match some specific field from both the arrays, like, maybe the ID. 

 

If they match, just filter on that. 

 

So, on left side do, something like this:

item()['responses']?['ID']

[Not exactly the above expression, something similar]

 

and before all of this take another apply to each, pass the http output of it, and on the right side of the filter, just, pass the item()['ID'],

expression related to this. 

 

I hope you got it...

 

Just made a demo for more information:

 

My Array 1:

Sundeep_Malik_0-1670312032290.png

 

My Array 2:

Sundeep_Malik_1-1670312047826.png

 

Then initialized an array variable. This would serve as the filtered array at the end:

Sundeep_Malik_2-1670312085013.png

 

Then this how the later flow looks like:

Sundeep_Malik_3-1670312127197.png

 

In the apply to each 1 I passed output of the compose 2 which is my second array. In your case it would be the array you are getting from the http response. I will match the ID value of second array to the id value of 1st array one by one with the help of this apply to each.

 

Inside apply to each the filter array:

Passed the output of array 1. 

On left side passing the item()?['ID'] of array 1.

On right side passing the ID of 2nd array with expression:

item('Apply_to_each)?['ID']

Sundeep_Malik_4-1670312288555.png

 

After this used another apply to each. I passed the body of filter array in it. So, by this if there is any null value, in the above filter, it will not go in the apply to each, and we will just append the filtered array in it. 

I am passing the item() in the append to each. So, it will just append the current item of the filtered array. This apply to each is inside the 1st apply to each only. 

Sundeep_Malik_5-1670312357952.png

Outside both the apply to each, I made a compose to get the value of the variable. 

Sundeep_Malik_6-1670312435696.png

 

Complete flow at the end for more info:

Sundeep_Malik_7-1670312462129.png

 

Output:

Sundeep_Malik_8-1670312493972.png

 

I hope this help. 🙂

View solution in original post

3 REPLIES 3
Sundeep_Malik
Community Champion
Community Champion

Hey @Moshema 

 

Not perfectly sure, but don't match array to an array, match some specific field from both the arrays, like, maybe the ID. 

 

If they match, just filter on that. 

 

So, on left side do, something like this:

item()['responses']?['ID']

[Not exactly the above expression, something similar]

 

and before all of this take another apply to each, pass the http output of it, and on the right side of the filter, just, pass the item()['ID'],

expression related to this. 

 

I hope you got it...

 

Just made a demo for more information:

 

My Array 1:

Sundeep_Malik_0-1670312032290.png

 

My Array 2:

Sundeep_Malik_1-1670312047826.png

 

Then initialized an array variable. This would serve as the filtered array at the end:

Sundeep_Malik_2-1670312085013.png

 

Then this how the later flow looks like:

Sundeep_Malik_3-1670312127197.png

 

In the apply to each 1 I passed output of the compose 2 which is my second array. In your case it would be the array you are getting from the http response. I will match the ID value of second array to the id value of 1st array one by one with the help of this apply to each.

 

Inside apply to each the filter array:

Passed the output of array 1. 

On left side passing the item()?['ID'] of array 1.

On right side passing the ID of 2nd array with expression:

item('Apply_to_each)?['ID']

Sundeep_Malik_4-1670312288555.png

 

After this used another apply to each. I passed the body of filter array in it. So, by this if there is any null value, in the above filter, it will not go in the apply to each, and we will just append the filtered array in it. 

I am passing the item() in the append to each. So, it will just append the current item of the filtered array. This apply to each is inside the 1st apply to each only. 

Sundeep_Malik_5-1670312357952.png

Outside both the apply to each, I made a compose to get the value of the variable. 

Sundeep_Malik_6-1670312435696.png

 

Complete flow at the end for more info:

Sundeep_Malik_7-1670312462129.png

 

Output:

Sundeep_Malik_8-1670312493972.png

 

I hope this help. 🙂

Moshema
Frequent Visitor

Thank you!!
Your solution + Compose for the variable worked!
Do you know maybe why a compose for the variable worked while working with the variable alone didn't?

Sundeep_Malik
Community Champion
Community Champion

Nice to hear that it worked. 🙂

 

Really didnt get your question there, can you elaborate or maybe even show it with the screenshot of that part. 

 

As much as I get, you were reading the result incorrectly, you might be just seeing the iterations which must be showing you single values, but when you used a compose and added the variable in it outside the apply to each, it showed you everything. 

In iterations, the append to array variable action does one by one, but when you see its output outside the apply to each you will see all the values. [According to my past experience, people do this a lot]

 

 

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (1,897)