Look up customer and for each loop error?

Solved

Look up customer and for each loop error?

SamuelR
Tourist
8 0 1

I'm working on a flow that looks up customers based on a specific tag. If a customer has this tag, I want to do two things:

  1. Assign 20 points to the customer (this JSON script works fine in other flows).
  2. Remove the tag used for the lookup (so the flow only runs once per customer).

The challenge is that the "For Each" loop can only connect to a single node, so I have to look up the same customers twice.

As a result, I end up with:

  • getCustomerDataForeachitem.id for assigning points.
  • getCustomerData1Foreachitem.id for removing the tag.

The Problem:

  • The points are being assigned twice to the customer's metafields, as if both customer lookup nodes are triggering it—even though they don’t have the same ID.
  • The process seems unstable—sometimes the tags are removed, and other times they are not.

Question:

Is there a better way to handle this, so I can assign points and remove the tag in a single lookup without duplication or inconsistency?

 

Schermafbeelding 2025-01-31 173925.pngSchermafbeelding 2025-01-31 173937.pngSchermafbeelding 2025-01-31 173947.pngSchermafbeelding 2025-01-31 173959.png

Accepted Solution (1)
paul_n
Shopify Staff
1584 171 364

This is an accepted solution.

You shouldn't be looping over the "GetCustomerData" in the liquid for the action. That is looping over all the customers returned. Instead you want to use the specific customer in that instance of the for each loop (it will have foreach in the name). 

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.

View solution in original post

Replies 4 (4)

paul_n
Shopify Staff
1584 171 364

You can do a single lookup and then use 2 for each loops, looping over the same list twice. Put the second loop in the "then" path of the first loop.

 

We do want to remove some restrictions on the "For each" loop, including allowing more than 1 action per loop. It's not close, though. 

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
SamuelR
Tourist
8 0 1

Hi Paul,

 

Thanks for the reply, this is how I started. But I got the same problems. With this setup (single lookup with 2 for each loops), it assigns the points 3 times to the customer metafield. +20 becomes +60. The get customer data lookup and both the for each loops seem to be a trigger for the JSON.

Schermafbeelding 2025-01-31 185402.png

paul_n
Shopify Staff
1584 171 364

This is an accepted solution.

You shouldn't be looping over the "GetCustomerData" in the liquid for the action. That is looping over all the customers returned. Instead you want to use the specific customer in that instance of the for each loop (it will have foreach in the name). 

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
SamuelR
Tourist
8 0 1

I see, that makes sense. It works now.

 

Thanks Paul!

 

Schermafbeelding 2025-01-31 200639.png