cancel
Showing results for 
Search instead for 
Did you mean: 

Filtering a list before iterating over it

eddabm
Deputy Chef I
Deputy Chef I

Hey all,

I have used the Python action to output a list, I've provided the schema and I can iterate over it without issue. However, what I would like to do is filter the list before iterating over it. So for example, the list contains an ID field, I can use .where(id: 123) to get just the hashes/objects I want. Problem is, I don't understand how I can use the output of my formula in my recipe. The input for the for each mode doesn't accept a formula, and I can't seem to find a way to update a variable. The only option I'm seeing right now is to make it part of my Python step, but I'd really prefer to use the built in functionality.

This maybe clearer, I want to filter 'user group reference' by the ID before passing it into the for each. 

Screenshot 2024-07-25 at 11.00.39.png

Does anyone know how I can approach this? 


1 ACCEPTED SOLUTION

mppowe
Executive Chef I
Executive Chef I

I've often been frustrated by this scenario too.  You may want to upvote this idea:
https://ideas.workato.com/app/#/case/187864?currentProductId=caf1efdf-1d7e-4b7b-aeb9-28e4b0f4b25c

The weird workaround I've used and heard from others is to use a Logger step where you do your .where function, then use a JSON parsing step where you enter a sample document (based your existing schema) and use your Message output and apply the .to_json formula on it.  Now you have a List that you can iterate over.

View solution in original post

3 REPLIES 3

mppowe
Executive Chef I
Executive Chef I

I've often been frustrated by this scenario too.  You may want to upvote this idea:
https://ideas.workato.com/app/#/case/187864?currentProductId=caf1efdf-1d7e-4b7b-aeb9-28e4b0f4b25c

The weird workaround I've used and heard from others is to use a Logger step where you do your .where function, then use a JSON parsing step where you enter a sample document (based your existing schema) and use your Message output and apply the .to_json formula on it.  Now you have a List that you can iterate over.

gary1
Executive Chef III
Executive Chef III

This is the way (but you could skip the logger step and do the .where on the input to the JSON parser action).

Gotta save those tasks! 😛

mppowe
Executive Chef I
Executive Chef I

Heh, true enough.  Task task task.  Though for bulk actions like this outside of a loop, sometimes I'll eat the task just for the sake of knowing the results step-by-step for future troubleshooting purposes.