Is this a bug or intended behavior?
I’m trying to create a flow that does the following:
-
Gets all customers without a specific tag
-
Loop through each customer and update their contact on an external app
-
Loop each customer again and update their shopify profile to add a tag so they don’t get pulled into the next time the flow runs
The issue I’m facing is that when I add the second for each flow, it removes the customer reference from the actions under the ‘do this for each item’ and only has the reference inside the then action’s for each item action.
Only way I can seem to get it to work is by doing another get customer data after the first for each, but that runs the risk of not processing the same customer from the first get customer data.
Hope this can help you:
This behavior is expected in Shopify Flow because each “For each” loop creates a new scope, and once you start another loop, it loses reference to the previous one. Instead of running a second “Get customer data,” try storing the customer data in a variable before the first loop and referencing that variable in the second loop.
If Shopify Flow doesn’t support variables for your case, a workaround is to nest the actions inside the same loop (i.e., update the contact first, then add the tag in the same loop)
How do you nest actions in the same loop? I can’t do multiple actions from one for each it seems, and my understanding is the ‘then’ happens after it finishes looping through everything.
Maybe you can consider try (if it works, please tell me)
Instead of using two separate “For each” loops, try doing both actions (updating the external app and adding the Shopify tag) within one loop.
- In the first loop (processing each customer from getCustomerData), update the contact in the external app.
- Then, in the same loop, immediately add the tag to ensure they don’t get pulled in the next run.
- This avoids losing the reference to the customer
You literally can’t do that… am I missing something? There is no way to connect “update a contact” action to either the for each action, nor the ‘add customer tags’ action.
Seems like a bug in my opinion. If I do second forEach action and then have a text field i can access the variable during the loop just fine. But if it’s a customer reference it freaks out as if it’s not there.