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:
Response:
HTTP response (source of the array I want to filter):
If anyone can help I'll be very grateful, thanks
Solved! Go to Solution.
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:
My Array 2:
Then initialized an array variable. This would serve as the filtered array at the end:
Then this how the later flow looks like:
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']
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.
Outside both the apply to each, I made a compose to get the value of the variable.
Complete flow at the end for more info:
Output:
I hope this help. 🙂
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:
My Array 2:
Then initialized an array variable. This would serve as the filtered array at the end:
Then this how the later flow looks like:
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']
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.
Outside both the apply to each, I made a compose to get the value of the variable.
Complete flow at the end for more info:
Output:
I hope this help. 🙂
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?
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]
User | Count |
---|---|
88 | |
39 | |
23 | |
20 | |
16 |
User | Count |
---|---|
127 | |
49 | |
46 | |
34 | |
25 |