UPDATE:
I tried the following flow:
The code in “run code” is the following:
export default function main({product}) {
// Exisitng Values in Metafield filters.farbe
const filtersFarbeMetafieldObject = product.metafields.find((metafield) => metafield.namespace === "filters" && metafield.key === "farbe");
const filtersFarbe = filtersFarbeMetafieldObject ? JSON.parse(filtersFarbeMetafieldObject.value) : [];
const colorValues = ["schwarz", "beige", "braun", "weiß", "grau", "grün", "orange", "lila", "gelb", "blau", "rosa", "rot","bunt"]; // Die Farbwerte, die du überprüfen möchtest
// Check whether the product label contains the colors
colorValues.forEach((colorValue) => {
if (product.metafields.some((metafield) => metafield.namespace === "mm-google-shopping" && metafield.key === "custom_label_2" && metafield.value.includes(colorValue))) {
if (!filtersFarbe.includes(colorValue)) {
filtersFarbe.push(colorValue);
}
}
});
// Output of a string that can be directly transmitted to a metafield update action return { filtersFarbe: JSON.stringify(filtersFarbe) };
}
I ran the flow and got the following error message:
I don’t know much about programming, which is why I can’t understand what I did wrong.
From an other member of this forum I was told that the problem is the definition of my metafield “filters.farbe”. It is currently not a JSON type metafield.
So I deleted the old filters.farbe and created a new one and now I am stuck here:
What goes into the field here now? Basically, it should contain all the possible colors (schwarz", “beige”, “braun”, “weiß”, “grau”, “grün”, “orange”, “lila”, “gelb”, “blau”, “rosa”, “rot”,“bunt”) and allow a list of values in that metafield. For example, when there’s a product that includes black and green color, both values should be sent to “filters.farbe” metafield for that product.
Thanks in advance.


