How to make sure product metafield is not one of the ones from a list of options

How to make sure product metafield is not one of the ones from a list of options

AH63935
Shopify Partner
24 1 24

I want to add a step where Flow will check if a product metafield is not one of the values from a list of values. For example if my product metafield is colors, I want to make sure the product metafield is not one of these (ie blue, green, purple, red, orange...). The list will probably be very large and variable so I need a way to store it somewhere and be able to change it as well. Is this able to be done in run code? And if so, can I get an example of how (have never used run code before) ? Thanks!!

Replies 2 (2)

Annieloveth
Shopify Partner
2 0 0

KIndly drop your webiste URL

ryan_i
Shopify Staff
22 5 8

Hi There,

You can certainly use "Run code" to achieve this. The JavaScript would be:

const denylist = [
  'blue',
  'green',
  'purple',
  'red',
  'orange'
];

export default function main() {
  return { denylist: denylist };
}

 

With the "Define outputs" section as:

"The output of Run Code"
type Output {
  "Colour denylist"
  denylist: [String!]!
}

This could then be used in a condition compared against a metafield (here I'm using a product variant metafield `custom.colour`):

Screenshot 2024-08-06 at 10.54.09 AM.png

 

- Finding Flow useful? Leave us a review.
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.