Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
I am adding a row to Google Sheets when certain things happen. Let's just say I'm using 'product added to store'.
I want to be able to have columns for each of the main metafields added to the item.
At the moment if you use the Namspace or Value variables it will just compile all the different metafields into a single cell.
I want to be able to have different columns for each metafield, but can't work out the liquid to do this.
I was trying something like this (where the bold text is my namespace.key:
{% for metafields_item in product.metafields %}
{% for metafields_item in product.department %}
{{metafields_item.value}}
{% endfor %}
{% endfor %}
It seems odd that there isn't a way to say that I only want to show the value of one particular metafield per column. I assume that must be possible and that I'm just missing something.
Does anyone know?
You cannot use namespace and key that way in Flow yet. You should remove that inner loop and add:
{% if metafields_item.key == "department" and metafields_item.namespace == "product" %}
{{ metafields_item.value }}
{% endif %}
Old comment edited to be replaced by reply above.
Ok.
Having looked over it further I think the issue may be in how I presented the prolem.
Let's say we have 2 metafield each with multiple options that can be added.
Metafield 1 | Metafield 2 |
Option 1 | Option A |
Option 2 | Option B |
Option 3 | Option C |
For the purposes of explaining this the bold ones are the ones I add to the product.
When this gets to the google sheet it gets recorded as below (where whitespace is added if options were used that weren't the first option available.
["Option 1"] |
["Option 2"] | ["Option A"] |
["Option B"] |
I need it to record values from the same namespace.key together i.e.
Option 1, Option 2 | Option A, Option B |
I suspect I need to use some combination of trim, remove (for the [""]) and join (to make it a comma separated list, but can't work it out.
If the google sheet connecter will always split MF values across multiple columns it is not usable by us. Suspect this may be a common issue for multi-select MFs.
Assuming you want to keep the comma, it needs to be escaped
{{- metafields_item.value | replace: ",","\," -}}
Hyphens remove the whitespace. If you want to remove [ and ] just add two more "replace" filters to the above code.
Thanks Paul.
There isn't actually a comma to keep. The metafield value split over different columns in sheet. What I want to do is keep all MF relating to any one particular namespace.key within the same cell and have them in a comma separated list, with all that whitespace removed.
Otherwise it become impossible to read the sheet as the MFs will not line up vertically with each other.
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024