We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Extracting metafield values from customer notes

Extracting metafield values from customer notes

tinus1424
Visitor
1 0 1

I want to extract a single line text value from the customer note once the customer is created but I am having trouble with new line processing in shopify flow and liquid. 

My update metafield action looks like this:

{% assign lines = customer.note | split: '\n' %}
{% for line in lines %}
{% if line contains 'website' %}
{% assign website = line | remove: 'website:' | strip %}
{% endif %}
{% endfor %}

but it won't split on \n no matter what. I have tried putting in an actual newline in the code, i have tried replacing the newline. Nothing seems to work. The only thing that does work is strip_newlines, but then I cannot separate it anymore.

Replies 2 (2)

tim
Shopify Partner
4812 598 1733

There is also this technique for splitting into lines:

{% capture newline %}
{% endcapture %}
{% assign lines = customer.note | split: newline %}

Just make sure there is no stray spaces inside capture

If my post is helpful, hit the thumb up button -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com

CodingFifty
Shopify Partner
1102 162 191

Hey! @tinus1424,


You're right—Shopify Flow and Liquid can behave unexpectedly when it comes to newline characters (\n), especially because how they're stored or passed in customer.note might not be consistent (e.g. it might be \r\n, actual newlines, or nothing visible).
Here’s a better approach to ensure you correctly split on actual line breaks in Shopify Flow:

{% assign lines = customer.note | newline_to_br | split: '<br />' %}
{% for line in lines %}
  {% if line contains 'website:' %}
    {% assign website = line | remove: 'website:' | strip %}
  {% endif %}
{% endfor %}

 

Coding Fifty || Shopify Partner
For any custom section queries, please visit: Fiverr Profile
Found my response useful? Like it and mark as Accepted Solution!
For additional discussions, reach out via: Email ID: codingfifty@gmail.com