Shopify Flow won't let me add delineators. All text in order notes now appear in my metafield

Hello Everyone,

I have an interesting issue I need help with.

I am using shopify flow to pull the PO# from order notes and add them into a order metafield. I managed to get it to work however I cannot seem to add delineators in the code as the templating language misinterprets it. So this means anything written after the PO will be picked up and moved to the metafield.

Here is the current code in action that doesn’t have :

{%- assign ordernote_lines = order.note | split: “
” -%}
{%- assign dataPO = “” -%}
{%- for line in ordernote_lines -%}
{%- if line contains “PO:” -%}
{%- assign parts = line | split: “PO:” -%}
{%- assign dataPO = line | remove: “PO:” | strip_newlines | strip -%}
{{ dataPO }}
{%- endif -%}
{%- endfor -%}

Here is the code I am trying to implement that uses a delineator that stops the data gathering at the first white space. It uses arrays to split the note into parts to parse out what is needed and what isn’t:

{%- assign ordernote_lines = order.note | split: “
” -%}
{%- assign dataPO = “” -%}
{%- for line in ordernote_lines -%}
{%- if line contains “PO:” -%}
{%- assign parts = line | split: “PO:” -%}
{%- assign po_number = parts[1] | split: " " -%}
{%- assign dataPO = po_number[0] | strip_newlines | strip -%}
{{- dataPO -}}
{%- endif -%}
{%- endfor -%}

<<>>

I get this error when I try to enter the code above and save it.

“order.note.1.0” is invalid. Replace this variable.

What can be done to make it see my array? or is there another way to take the PO from the rest

Hi @EES1 ,

Have you looked into implementing this using the Run Code action? You’ll have more control with JavaScript over Liquid when working with arrays and string parsing. You can use the output from the code action in the metafield action.

Hope that helps!

If you don’t go the run code route, I would enter this code into a Log Output action and print out variables to see what exists as each step.

Also, if you keep the liquid, Flow does not support using [ ] to access list elements.