Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
Hi,
I am trying to understand the code to add to the value text box of the update product variant metafield action step in a flow.
I want the flow to update a variant metafield with the value from another metafield from the same variant if it has a value.
I am trying to repurpose the shopify code example for listing the colours:
{% capture mf_value %}
{%- for tags_item in product.tags -%}
{%- if tags_item contains "color:" -%}
"{{- tags_item | remove_first: "color:" | strip -}}",
{%- endif -%}
{%- endfor -%}
{% endcapture -%}
[{{mf_value | remove_last: ","}}]
by changing it to:
{% capture mf_value %}
{%- for metafields_item in productVariant.metafields -%}
{%- if metafields_item.key contains "sell" -%}
"{{metafields_item.value}}"
{%- endif -%}
{%- endfor -%}
{% endcapture -%}
In my scenario I have a variant metafield with namespace "cross" and key "sell". If this metafield has text in it I want to pull that value into the variant metafield I am updating with the flow action.
I am currently getting the following error when the flow runs of:
Got error updating metafield: "Value can't be blank." For value: "", Type: single_line_text_field
Can anyone help?
Many thanks
Mark
Solved! Go to the solution
This is an accepted solution.
Update:
I have worked this out using the other example for sending a metafield in an email:
{% assign hold_note = order.metafields | where: "namespace", "custom" | where: "key", "hold_note" | first %}
The order has a hold note of: {{ hold_note.value }}
I tweaked this to be:
{% assign hold_note = productVariant.metafields | where: "namespace", "cross" | where: "key", "sell" | first %}{{ hold_note.value }}
also needed to remember that if you have any line breaks in the value text box then you will get a gotcha \n error which you'll then spend time trying to remove, replace, strip etc, whereas you just need to keep your code on one single line without any returns.
This is an accepted solution.
Update:
I have worked this out using the other example for sending a metafield in an email:
{% assign hold_note = order.metafields | where: "namespace", "custom" | where: "key", "hold_note" | first %}
The order has a hold note of: {{ hold_note.value }}
I tweaked this to be:
{% assign hold_note = productVariant.metafields | where: "namespace", "cross" | where: "key", "sell" | first %}{{ hold_note.value }}
also needed to remember that if you have any line breaks in the value text box then you will get a gotcha \n error which you'll then spend time trying to remove, replace, strip etc, whereas you just need to keep your code on one single line without any returns.
Hi MarkMcC
Glad you were able to get that sorted out. One thing to keep in mind with Liquid is that you can use hyphens on the tags to avoid new lines like this:
{%- assign hold_note = productVariant.metafields | where: "namespace", "cross" | where: "key", "sell" | first -%}
{{ hold_note.value }}
In that example, it should work the same as your single line example.
Learn how to expand your operations internationally with Shopify Academy’s learning path...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025Expand into selling wholesale with Shopify Academy’s learning path, B2B on Shopify: Lau...
By Shopify Jan 28, 2025