Condition to make the flow check for certain values in a Metafield

Solved

Condition to make the flow check for certain values in a Metafield

Kilian_A
Tourist
4 0 1

Hi,

 

I want to create a flow where products that are on Draft and have more than 0 stock are put back on Active. But as extra condition, I want to make it check if certain values are not filled in a metafield. I can't make the flow values match the orginal ones. They are never recognised, so I need some help to formulate the right value in the flow so it matches. The values in the metafields are list items, 3 of those values if filled in should stop the flow, these list items are:

  • Draft - Out of Stock (Shopify stock incorrect)
  • Draft - Quarantine
  • Draft - Unsendable Products (food, glass, ...)

 

I provided a screenshot below (can't seem to add export of the flow?). I tried many other things, this is just the latest example of one that doesn't work. Tried both with string and JSON values. I'm not a coder at all, so I think I'm just missing the right way to input the values?

 

Thanks in advance!!!

 

Kilian_A_1-1749042550169.png

 

Accepted Solution (1)

paul_n
Shopify Staff
1818 199 432

This is an accepted solution.

Don't loop over metafields like this. If any one of them has a large value, it can stop your automation from working, because you'll hit an API limit. 

 

Instead you add the metafields individually to the workflow and then you can check the value for a single metafield. To do that, you choose "product / metafield" not "Metafields" plural. Instructions https://help.shopify.com/en/manual/shopify-flow/concepts/metafields#get-metafield-data

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 6 (6)

StevenT_A7
Explorer
161 13 17

Hi @Kilian_A , 

 

Since your metafield is a list of values, each value is stored as a separate string item, not as one large JSON string.

 

Rather than comparing against a full JSON string (like ["Draft - Out of Stock (Shopify stock incorrect)"]), you need to check whether any list item matches one of the blocked values, like this:

 

In your third condition block, change it to:

IF: Any of product / metafields
Metafield list item value → is equal to → Draft - Out of Stock (Shopify stock incorrect)

Click Add criteria

Metafield list item value → is equal to → Draft - Quarantine

Click Add criteria

Metafield list item value → is equal to → Draft - Unsendable Products (food, glass, ...)

Change the condition mode to OR between them

Then under "If true", use Fail workflow

Under "If false", continue to set product to Active

 

Please try this once and do let me know if issue persists ! 

Thanks ! 

 

Steven Taylor
302-260-8345
Kilian_A
Tourist
4 0 1

Hi,

 

Should I keep using the "json value" or switch to "string" again like the screenshot?

Kilian_A_1-1749047670644.png

Here I tried your recommendations with the "json value" still and that didn't work.

 

Kilian_A_0-1749047531926.png

 

This is the output of the condition for a product that had the "Draft - Quarantine" filled in the metafield:

 

Kilian_A_2-1749048170389.png

["Draft - Quarantine"] is added after the  "," each time at the end (cut of in the screenshot and can't have it shown in flow for some reason)

 

 

StevenT_A7
Explorer
161 13 17

Hi @Kilian_A , 

 

From the screenshots:

Your metafield values are stored like this: ["Draft - Quarantine"]

But Shopify Flow evaluates each item in a list individually when you use the correct field, not json value.

 

What to do instead:-
Use:

Field: product / metafields

Condition Type: Metafield list item

Comparison: is equal to

Value: Draft - Quarantine (exact plain string, no brackets or JSON)

 

Then repeat the condition with OR for:

Draft - Out of Stock (Shopify stock incorrect)

Draft - Unsendable Products (food, glass, ...)

 

Final Condition Block Setup
IF → Any of product / metafields

Metafield list item is equal to Draft - Out of Stock (Shopify stock incorrect)

OR

Metafield list item is equal to Draft - Quarantine

OR

Metafield list item is equal to Draft - Unsendable Products (food, glass, ...)

 

Don’t use json value, that is meant for comparing raw JSON arrays, and your flow won’t match individual list items properly using that.


After setting this up:

Add a product with only Draft - Quarantine in the metafield

Change stock to trigger the flow

It should now match and block the flow

Let me know your metafield’s namespace and key (e.g., custom.status_blocking) if you want me to show exactly where to apply this.

 

Thanks ! 

Steven Taylor
302-260-8345
Kilian_A
Tourist
4 0 1

Hi Steven,

 

Got it fixed with the recommendations of another comment.

Appreciate you willing to help though!

 

Cheers

paul_n
Shopify Staff
1818 199 432

This is an accepted solution.

Don't loop over metafields like this. If any one of them has a large value, it can stop your automation from working, because you'll hit an API limit. 

 

Instead you add the metafields individually to the workflow and then you can check the value for a single metafield. To do that, you choose "product / metafield" not "Metafields" plural. Instructions https://help.shopify.com/en/manual/shopify-flow/concepts/metafields#get-metafield-data

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.
Kilian_A
Tourist
4 0 1

This worked like a charm!

 

I have stumbled on it before, but I was a bit lost with the Alias before, now it made sense.

 

Thanks!!!