Accessing custom customer metafields as a condition

Hey all,

I’ve been trying to troubleshoot a Shopify flow condition for a while, and thought I’d turn it to the group. Right now I have a customer metafield with the key of welcome_flow_email. If the metafield is blank, I want to send the user one way, and if not, then send them the other way; however, no matter what I try, I can’t seem to surface the data. I’ve tried logging data but everything is coming back as blank, so I must be missing a key piece.

Here are some screenshots that may help:
Metafield definition: https://screenshot.click/07-12-21vk3-i72da.png
Shopify Flow condition: https://screenshot.click/07-13-uk08k-miwio.png

Any and all help is sincerely appreciated. Thank you all!

1 Like

Hey @Puzzery !

I am not sure if this is the entire problem here, but one thing I would suggest is restructuring the second part of your condition so that it checking the same item. Specifically, use the “Add criteria for same list item” link to set up the condition for metafield_item.value is empty or does not exist

If you’re still having problems after this and need to troubleshoot further, use the following syntax for your log action to log the metafield value:

{% for metafields_item in customer.metafields %}
  {% if metafields_item.namespace == "custom" and metafields_item.key == "welcome_flow_email" %}    
      {{metafields_item.value}}
  {% endif %}
{% endfor %}

2 Likes

Hey @Brett_Helium ,

Thank you for such a fast, and detailed response - I sincerely appreciate it!

Here’s a bit of overview:

  • I went in and tried combining the item conditions (photo attached)
  • I also added a log, as requested, after the fail state to try and catch the issue
  • And yes, often the most important step, saved the flow

After that I ran it, confirmed that the process went through that specific flow (shown in logs, and the actions at the end of the specific branch with the metafield conditional and logs were carried out to prove it).

Here’s a screenshot with some details: https://screenshot.click/07-00-nfm07-eocjs.png

Brett, you’ve been an all-star already, but if you have any other suggestions, I am definitely interested. Whatever the case, thank you again for your help :slightly_smiling_face:

Can you confirm that the metafield exists on the customer? If you open up your customer you should see a list of metafields.

If the metafield doesn’t exist on the customer, then none of the customer metafields will match the key you’re looking for. You’ll need an additional condition to check if the metafield namespace + key exists or not.

1 Like

Hey @Jeff-Armstrong ,

Thank you for the reply! Yes, I can confirm that the metafield exists on this customer account (and all others). It’s blank, but that’s what I want to be checking for - if blank, do X, if not do Y. Here’s an image for reference, in case it helps:

Customer page: https://screenshot.click/08-12-tuvir-h32r8.png

If there is anything else I can do to help troubleshoot this, then please let me know. Thank you!

That is showing the the metafield definition exits, but since it’s not set, it literally doesn’t show up in the API that Flow calls. Since there are 0 metafields returned, your logic actually never runs.

I might instead reverse the logic to check if “none of” the metafields match your condition. For “none” it will be true when that is empty and false if the condition matches. You can probably just check for the key name in that.

2 Likes

Thank you @paul_n - that was the exact thing I was missing. Thank you (and everyone) for the guidance! ?‍

For anyone looking for something similar, here’s the end result: https://screenshot.click/08-37-x3hbn-d35xf.png

Flow just launched improved metafield support, which makes it easier to find and use metafield data in Flow: https://changelog.shopify.com/posts/shopify-flow-access-typed-metafields

1 Like

This is awesome news @paul_n , thanks for sharing! :raising_hands: