This topic was automatically generated from Slack. You can find the original thread here.
any clever way to iterate over an array received from one step and run a Google Drive step for each result? Keen to use the built in connector rather than having to revert to node for the loop.
To iterate over an array received from one step and run a Google Drive step for each result using Pipedream’s built-in connectors, you can utilize the “Loop” feature in Pipedream. This feature allows you to iterate over an array and perform actions for each item in the array without writing custom Node.js code. Here’s a step-by-step guide on how to achieve this: 1. Set up your trigger and initial steps: Ensure you have a trigger that provides the array you want to iterate over. This could be any trigger that outputs an array in its step exports. 2. Add a Loop step: - In your workflow, click on the “+” button to add a new step. - Select “Loop” from the list of available actions. - In the Loop configuration, specify the array you want to iterate over. You can reference the array from a previous step using the steps object, like steps.previous_step_name.$return_value. 3. Configure the Google Drive action: - Inside the Loop step, add a new action by clicking the “+” button. - Search for the Google Drive app and select the desired action you want to perform for each item in the array (e.g., “Upload File”, “Create Folder”, etc.). - Configure the Google Drive action using the current item from the loop. You can reference the current item using the item variable provided by the Loop step. 4. Test your workflow: - Once you have configured the Loop and Google Drive action, test your workflow to ensure it iterates over the array and performs the Google Drive action for each item. By using the Loop feature, you can efficiently iterate over arrays and perform actions without writing custom code, leveraging Pipedream’s built-in connectors. If you encounter any issues or need further assistance, feel free to reach out to Pipedream support at Support - Pipedream.
Pipedream doesn’t have a built-in loop component, but you can implement loops using code steps in your workflows. Here’s a basic example of how you can create a loop using a Node.js code step: ```
export default defineComponent({ async run({ steps, $ }) { const items = [1, 2, 3, 4, 5]; // Example array to loop over const results = ; for (const item of items) { // Perform some operation on each item const result = item * 2; // Example operation results.push(result); } return results; // Return the results of the loop }, });