Update Google: Color Variant Metafield based on Product Options containing a Color Value

Update Google: Color Variant Metafield based on Product Options containing a Color Value

steveking8
Visitor
2 0 0

Hello,

 

I am trying to write a Flow which triggers on a Product variant inventory quantity being changed, the trigger works. The check if I am using is if options_item.position = 1 and options_item.name = color, that also works and tells me that color is is in the first position. Once I get it to work I would create two more check ifs for position 2 and 3, maybe there is a way to do all in one but I am a novice. 

 

steveking8_0-1737731366589.png

 

My issue is the Action step, specifically the code I need to grab the option name from position 1, or the position where options_item.name = color.

 

steveking8_1-1737731451014.png

 

The above returns the following error for the product I am testing. Exception: Got error updating metafield: "Value must be a single line text string." For value: "\n Orange\n\n 28mm\n\n\n", Type: single_line_text_field

 

This leads me to believe I either need an if statement to only return the option value in position 1 or there some sort of other reference I am missing. Any help would be very appreciated! I intend to the same with the Google: Size Metafield.

 

Steve

Replies 2 (2)

RPiii
Shopify Staff
156 27 46

Hi Steve 👋 For the metafield "mm-google-shopping.color", the namespace is the string before the period and the key is the string after. In your step configuration, the namespace should be "mm-google-shopping" and the key should be "color".

steveking8
Visitor
2 0 0

Thank you, I will make that change. But I don't think that fully solves my problem because I want it to only return the value of the Option with name matching color, in this case that is position 1. Can you help with the code needed?