Is It Possible to Filter Two Steps from the Previous Response in One Filter Step Instead of Two?

This topic was automatically generated from Slack. You can find the original thread here.

Hey using Filter step, is it possible to filter two steps from the previous response, and end or continue with the workflow.
Right now I have to create one filter to check one step, and then continue to the other step to check the other condition.
But thats two steps, can I have just one?

To achieve the goal of filtering based on conditions from two different steps in a single Filter step, you can combine the conditions using logical operators (like && for AND, || for OR) within a single Filter action. This allows you to evaluate multiple conditions and decide whether to continue or end the workflow based on the combined result. Unfortunately, the provided documentation does not include a direct example of combining conditions from two steps in a single Filter action. However, I can guide you on how you might approach this based on the capabilities of Pipedream workflows and the general use of the Filter action. Here’s a conceptual example of how you might structure your code within a Filter step to check conditions from two previous steps: export default defineComponent({ async run({ steps, $ }) { // Example conditions from two different steps let condition1 = steps.step1.response.condition; // Condition from step1 let condition2 = steps.step2.response.condition; // Condition from step2 // Combine conditions using logical operators if (condition1 && condition2) { // If both conditions are true, continue with the workflow $.export("$summary", "Both conditions met, continuing workflow."); } else { // If any condition is false, end the workflow early $.flow.exit("Ending workflow early because one or more conditions are not met"); } }, }) In this example, condition1 and condition2 represent the conditions you’re checking from two different steps (step1 and step2). You can replace these with the actual conditions you need to check. The logical operator && is used to ensure both conditions must be true to continue the workflow. If either condition is false, the workflow ends early. Remember, this is a conceptual example. You’ll need to adjust the steps.step1.response.condition and steps.step2.response.condition parts to match the actual structure of the data you’re working with from your previous steps. This approach allows you to consolidate your condition checks into a single Filter step, making your workflow more efficient and easier to manage.

This is all going to get a lot easier when we ship native support for branching, which is coming soon :slightly_smiling_face:

For now, the answer is here.