Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Re: Using flow to update a variant metafield

Solved

How to correctly update a variant metafield using flow?

mamanova
Tourist
7 0 1

Hi experts,

Sorry, it is partly in dutch! let me know if you need anything to be translated.

I created a flow that updates a variant metafield to the variant when it is created.

Now everything runs fine. Only thing is.

When the metafield is updated (created) it will not be the one I want to be updated. It will show as a Non structured metafieldScherm­afbeelding 2024-02-08 om 13.01.23.png

 

While I want it to be the following metafield: (in the added picture I updated the metafield manually)

Scherm­afbeelding 2024-02-08 om 13.01.11.png

 

Now this might be because the variant metafield I created has pre made answers. I added the page below:

Scherm­afbeelding 2024-02-08 om 13.46.44.pngScherm­afbeelding 2024-02-08 om 13.46.54.pngScherm­afbeelding 2024-02-08 om 13.47.02.png


 

I also added a screenshot of the flow:

Scherm­afbeelding 2024-02-08 om 13.48.29.png

Please let me know what to try?

Kind regards,
Pim

Accepted Solution (1)
paul_n
Shopify Staff
1433 157 332

This is an accepted solution.

There is an option ... in English it is called "List of Single Line Strings" as shown in your screenshot above.

 

When you update that value, the list must look like ["item1", "item2"]

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.

View solution in original post

Replies 8 (8)

Jeff-Armstrong
Shopify Staff
35 3 3

The metafield namespace and key you're using in Flow do not match the metafield definition you created.

Your metafield definition has namespace of `Variant_field` and key of `maten_van_varianten`.

Your workflow is using namespace `Maat` (which is the name of the metafield, not the namespace), and key of `Variant_field.maten_van_varianten` (which is actually the namespace and key combined).

You'll need to update your workflow to use the namespace and key as defined in the metafield definition.

To learn more visit the Shopify Help Center or the Community Blog.

mamanova
Tourist
7 0 1

Hi Jeff,
Thank you so much for taking the time to help. 

Your answer makes sense. I changed it and now get the following error:

8 feb 2024 om 18:46
Got error updating metafield: "Value is invalid JSON: unexpected token at 'Prematuur'." For value: "Prematuur", Type: list.single_line_text_field

Do you have any idea what I need to do?

I tried looking for "list.single_line_text_field" as the option:

Scherm­afbeelding 2024-02-08 om 18.52.37.pngScherm­afbeelding 2024-02-08 om 18.52.24.png
Jeff-Armstrong
Shopify Staff
35 3 3

In your metafield definition, you defined it as a single line of text, one word.
You'd need to select `Single line text` as the type in Flow to match that.

To learn more visit the Shopify Help Center or the Community Blog.

mamanova
Tourist
7 0 1

Hi jeff,

 

Thanks again for the reply. 

I had it in single line text (after I changed the namesapce and key). I still got an error:

 

Scherm­afbeelding 2024-02-09 om 09.50.09.png

 

Can you please let me know If I need to adjust something here: 

Scherm­afbeelding 2024-02-09 om 09.47.52.pngScherm­afbeelding 2024-02-09 om 09.48.08.png

Jeff-Armstrong
Shopify Staff
35 3 3

It looks like you have `Lijst met waarden` selected on the metafield definition, so this will expect a list of single line strings.
You'll need to create a new metafield definition if you only want a single value to be stored per key.
If you want multiple values to be stored for a single metafield key, then you'll need to select `list of single line strings` as the type in Flow. Since the value is now a list of values type, your value field in Flow also needs to be a list, not just a single string.

To learn more visit the Shopify Help Center or the Community Blog.

mamanova
Tourist
7 0 1

Hi Jeff,

 

Thanks again.

The problem is, I tried this already and that will result in the following:

 

Scherm­afbeelding 2024-02-09 om 20.58.46.png

 

The problem is: there is not "list.single_line_text_field" option.....

I guess it is just not possible...?

paul_n
Shopify Staff
1433 157 332

This is an accepted solution.

There is an option ... in English it is called "List of Single Line Strings" as shown in your screenshot above.

 

When you update that value, the list must look like ["item1", "item2"]

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
mamanova
Tourist
7 0 1

Hi Paul,

Thanks a lot! The input value was the problem! Changed it to: ["item1", "item2"] and now it works.