Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
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
Hi all,
For my products, I have a metafield that defines length (.custom.length), and one that defines shape(.custom.shape).
I am trying to create a flow, where when triggered, updates the cutline metafield (theme.cutline) to their length and shape values. All three metafields are single lined texts. (So for example length value = Medium and shape value = Oval, cutline value with be "Medium Oval"
After research I see that for liquid I need to do something like this:
{% for metafields_item in product.metafields %} {% if metafields_item.namespace == "custom" and metafields_item.key == "length" %} {{metafields_item.value}} {% endif %} {% endfor %}
I've also tried this:
{% for metafields_item in product.metafields %} {% if metafields_item.namespace == "custom" and metafields_item.key == "length" %} {% assign length_value = metafields_item.value %} {% endif %} {% endfor %} {{ length_value }}
But both returns this when run:
Got error updating metafield: "Value must be a single line text string." For value: "\n \n Medium\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n\n", Type: single_line_text_field
Is there any way I can fix this? Thank you!
Solved! Go to the solution
This is an accepted solution.
Try using hyphens to eliminate the newlines:
{%- for metafields_item in product.metafields -%} {%- if metafields_item.namespace == "custom" and metafields_item.key == "length" -%} {{- metafields_item.value -}} {%- endif -%} {%- endfor -%}
This is an accepted solution.
Try using hyphens to eliminate the newlines:
{%- for metafields_item in product.metafields -%} {%- if metafields_item.namespace == "custom" and metafields_item.key == "length" -%} {{- metafields_item.value -}} {%- endif -%} {%- endfor -%}
This worked perfectly! Thank you!
Flow just launched improved metafield support, which makes it easier to find and use metafield data in Flow: https://changelog.shopify.com/posts/shopify-flow-access-typed-metafields
Hi, just tried it. Worked perfectly, thanks!