Flow: Adding rows to spread sheets from "Get customer data" in proper formated lines

RennWelten
Excursionist
29 3 4

Hi everyone!

 

I recently created a workflow that uses "Get customer data", checks a condition for certain tags and afterwards is ment to add lines to a spreadsheet, data of every customer in a new line.

 

For some off reason or from my own stupidity I cant get it to work properly and Flow adds all the data into one single row within the spreadsheet.

 

Here the row content I used:

 

{% for getCustomerData_item in getCustomerData %}
{{getCustomerData_item.firstName}},
{{getCustomerData_item.lastName}},
{{getCustomerData_item.email}},
{% for getCustomerData_item in getCustomerData %}
{% for tags_item in getCustomerData_item.tags %}
{{tags_item}},
{% endfor %}
{% endfor %}
{% endfor %}

 

Anyone has an idea what I am missing in the variables to have every customers data in a single line?

 

Help would be highly appreciated!

 

Armin

Replies 6 (6)

RennWelten
Excursionist
29 3 4

Update:

 

Now I got it to work at least in some way. The customers data is still not in one line for each customer. Instead now all the first names are in one cell, the last names in one cell, the mail adress and the tags. So it fills only 4 cells in all instead of x lines with 4 cell, each line for one customer.

Here the row content I am now using:

 

{% for getCustomerData_item in getCustomerData %}
{{getCustomerData_item.firstName}}
{% endfor %},
{% for getCustomerData_item in getCustomerData %}
{{getCustomerData_item.lastName}}
{% endfor %},
{% for getCustomerData_item in getCustomerData %}
{{getCustomerData_item.email}}
{% endfor %},
{% for getCustomerData_item in getCustomerData %}
{% for tags_item in getCustomerData_item.tags %}
{{tags_item}}
{% endfor %}
{% endfor %}

 

So basicly, although it changed, I am still searching for a way to skip to the next row after each customers data ...

 

Kindest regards!

 

Armin

paul_n
Shopify Staff
1011 133 242

You cannot add multiple rows in one Sheets action, unless you write a script in Sheets. 

 

The solution is to use a For Each loop to repeatedly call "Add row". 

 

After the condition you mentioned, use a "For Each" loop action. Inside that action you can call "Add row to Sheets". 

 

Do not use your second attempt at the code...multiple loops over the same thing is almost never right. 

 

Your code might look something like this:

 

{{getCustomerDataForeachitem.firstName}},
{{getCustomerDataForeachitem.lastName}},
{% for tags_item in getCustomerDataForeachitem.tags %}
{{tags_item}}-
{% endfor %}

 

 

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.
3FIVE4
Visitor
2 0 0

Hey Paul,

 

Where exactly do I add the "For Each" loops? I cannot see where you have called an "add row to sheets" within the condition.

Could you help me with adding this "foreach" loop to my variables? I just want it to print out each order line item in separate rows like the standard "export orders" does...

 

 

{{order.name}},
{% for lineItems_item in order.lineItems %}
  {{lineItems_item.quantity}},
{% endfor %},
{% for lineItems_item in order.lineItems %}
  {{lineItems_item.name}}
{% endfor %},
{{order.customer.displayName}}, 
{{order.customer.numberOfOrders}},
{% for tags_item in order.tags %}
  {{tags_item}}
{% endfor %},

 


@paul_n wrote:

You cannot add multiple rows in one Sheets action, unless you write a script in Sheets. 

 

The solution is to use a For Each loop to repeatedly call "Add row". 

 

After the condition you mentioned, use a "For Each" loop action. Inside that action you can call "Add row to Sheets". 

 

Do not use your second attempt at the code...multiple loops over the same thing is almost never right. 

 

Your code might look something like this:

 

 

{{getCustomerDataForeachitem.firstName}},
{{getCustomerDataForeachitem.lastName}},
{% for tags_item in getCustomerDataForeachitem.tags %}
{{tags_item}}-
{% endfor %}

 

 

 


paul_n
Shopify Staff
1011 133 242

It will look like this roughly...

23-04-7dk54-3t0vy

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.
3FIVE4
Visitor
2 0 0

Hey Paul, 

 

Thanks for the insight! I have added this to the flow but now it just prints the same data on 3 lines...

3FIVE4_2-1677182419410.png

 

 

Could you explain how I get it to print each line item on its own line? Like the order export sheet does.

 

This is my code:

 

{{order.name}},
{% for lineItems_item in order.lineItems %}
  {{lineItems_item.quantity}}
{% endfor %},
{% for lineItems_item in order.lineItems %}
  {{lineItems_item.name}}
{% endfor %},
{{order.customer.displayName}}, 
{{order.customer.numberOfOrders}},
{% for tags_item in order.tags %}
  {{tags_item}}
{% endfor %}

 

 

And this is my Flow:

3FIVE4_1-1677182351176.png

 

 

paul_n
Shopify Staff
1011 133 242

You are using the wrong variable. You don't need to loop over lineitems in liquid because For Each is doing it for you. Click "Add a variable" and choose: 

23-50-xus9u-b0237

 

We have a template that shows this here:

https://shopify.com/admin/apps/flow/web/v2/editor/templates/e048b50b-63a9-4827-91fc-f9d0e08a49b8

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.