How to separate metafields into different Google Sheets columns?

Topic summary

Goal: log product metafields to Google Sheets via Shopify Flow so each specific namespace.key maps to its own column, and multi-select values appear together in a single cell.

Initial issue: Looping over product.department isn’t supported in Flow. Use a single loop over product.metafields and conditionally output one field:

  • If metafields_item.key == “department” and metafields_item.namespace == “product”, output metafields_item.value.

Multi-select complication: Selected options for two metafields are appearing split across multiple columns with extra whitespace and brackets. Desired output is a single cell per metafield, e.g., “Option 1, Option 2” and “Option A, Option B”.

Connector behavior: The Google Sheets action splits by commas, so values containing “,” are separated into columns. Suggested mitigation:

  • Escape commas (replace “,” with “,”) or replace with a space.
  • Trim Liquid whitespace using hyphens and remove brackets with additional replace filters.

Status: Partial guidance provided (conditional filtering and comma handling). There is disagreement about whether commas exist in the payload causing the split. No confirmed final fix; discussion remains open.

Notes:

  • Metafields: custom product data identified by namespace.key.
  • Liquid: templating language used in Flow templates.
Summarized with AI on February 4. AI used: gpt-5.

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 %}

Love this! Thanks @paul_n

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.

It split over multiple columns because it has a comma in it and the Sheets
action will split by comma. If you want them in the same column, you need
to keep or replace (maybe with a space, " ") the original comma