Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Customer Metafileds update from customer notes

Solved

Customer Metafileds update from customer notes

dasoljong92
New Member
4 0 0

Hello,

I have customer information, gender, and birthday, in the customer note section and I'd like to add the info into the customer metafield section automatically. 
I tried to do this with Shopify flow but it doesn't work at all.

How do I have to edit the flow?
Plz help!

 

 

dasoljong92_0-1702287411017.png

 

 

 

 

dasoljong92_1-1702287138295.png

 

 

Accepted Solutions (2)
TrustedSupport
Shopify Partner
6 2 2

This is an accepted solution.

My fault Dasonjong,

 

In order to access the first and last element, you need to do this:

 

birthday | last

 

 

I've been trying the code and it works fine with the above-mentioned, except that for some reason, shopify adds some extra newlines characters. You will need a way to remove them in order to make this approach to work. for reference:

 

gender:

{% assign lines = customer.note | newline_to_br | split: '<br />' %}
{% assign gender = lines | first | split: ':' %}
{{ gender | last }}

 

birthday:

{% assign lines = customer.note | newline_to_br | split: '<br />' %}
{% assign birthday = lines | last | split: ':' %}
{{ birthday | last }}

 

Hope this helps.

 

 

 

 

 

 

Check out our subscription! Get all the help you need for your shop.



www.trustedsupport.shop

View solution in original post

paul_n
Shopify Staff
1429 156 330

This is an accepted solution.

The tags themselves add newline characters. You can remove them by using hyphens in that tags.  For example, this will remove whitespace before and after the opening {% and closing %}

{%- assign lines = customer.note | newline_to_br | split: '<br />' -%}

 

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 9 (9)

TrustedSupport
Shopify Partner
6 2 2

Hi Dasoljong,

 

I noticed that your notes have multiple lines with different fields. Since notes is a text box, your automation will fail. The reason is that when  you are trying to assign the result of getting the notes and removing 'birthday', the resulting output will be:

 

"gender:female

1992-07-08"

 

and this will not fit in a date shopify field. Can you try with just the birthday in the notes and see if it works that way?

Check out our subscription! Get all the help you need for your shop.



www.trustedsupport.shop
dasoljong92
New Member
4 0 0

Hello,

Just birthday, it worked.

However, I need gender and birthday.

Isn't it possible?

TrustedSupport
Shopify Partner
6 2 2

You can try something like this on the value section:

 

 {% assign lines = customer.notes | newline_to_br | split: '<br />' %}
{% assign gender = lines[0] | split: ':' %}
{{ gender[1] }}

 

for the other field

 

{% assign lines = customer.notes | newline_to_br | split: '<br />' %}
{% assign birthday = lines[1] | split: ':' %}
{{ birthday[1] }}

 

 

Remember to mark the solution and like it! 😀

 

 

 

 

Check out our subscription! Get all the help you need for your shop.



www.trustedsupport.shop
paul_n
Shopify Staff
1429 156 330

FYI, you cannot access list values with syntax like `line[0]` in Flow.

 

That said, in this case, you can iterate over that list using a loop or use the tag "first" or "last". 

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.
TrustedSupport
Shopify Partner
6 2 2

Good point, Paul. I tried with plain liquid, not inside a workflow.

 

for the case DasolJol was proposing, and as Paul said, something like that should work:

 

 {% assign lines = customer.notes | newline_to_br | split: '<br />' %}
{% assign gender = lines.first | split: ':' %}
{{ gender.last }}

 

for the other field

 

{% assign lines = customer.notes | newline_to_br | split: '<br />' %}
{% assign birthday = lines.last| split: ':' %}
{{ birthday.last }}



If you want to add more fields, then the logic will need to change.

 

Check out our subscription! Get all the help you need for your shop.



www.trustedsupport.shop
dasoljong92
New Member
4 0 0

Hello,

Thank you for your help!
However, I tried with the code above, it does not work.

dasoljong92_0-1702426609025.png

It said, "notes" is invalid. So I changed it to "note".

 

dasoljong92_1-1702426659952.png

After that, it said "customer.note.last.last" is invalid. Replace this variable.

 

Could you help me with this error?

TrustedSupport
Shopify Partner
6 2 2

This is an accepted solution.

My fault Dasonjong,

 

In order to access the first and last element, you need to do this:

 

birthday | last

 

 

I've been trying the code and it works fine with the above-mentioned, except that for some reason, shopify adds some extra newlines characters. You will need a way to remove them in order to make this approach to work. for reference:

 

gender:

{% assign lines = customer.note | newline_to_br | split: '<br />' %}
{% assign gender = lines | first | split: ':' %}
{{ gender | last }}

 

birthday:

{% assign lines = customer.note | newline_to_br | split: '<br />' %}
{% assign birthday = lines | last | split: ':' %}
{{ birthday | last }}

 

Hope this helps.

 

 

 

 

 

 

Check out our subscription! Get all the help you need for your shop.



www.trustedsupport.shop
paul_n
Shopify Staff
1429 156 330

This is an accepted solution.

The tags themselves add newline characters. You can remove them by using hyphens in that tags.  For example, this will remove whitespace before and after the opening {% and closing %}

{%- assign lines = customer.note | newline_to_br | split: '<br />' -%}

 

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.
dasoljong92
New Member
4 0 0

Thank you so much!
It works!