Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
Hey,
I'm currently trying to hide a product with the workflow below, all of it works apart from the date comparison.
The metafields_item.value that I'm trying to compare is a metafield stored as a date. When I sent metafields_item.value to my email to check the value it returned a string YYYY-MM-DD so i've tried to compare it too {{ "now" | date: "%Y-%m-%d" }} this doesn't work I've also tried to compare it to {{ "now" | date: "%Y-%m-%d" | date: '%s' }} this also didn't work.
Have also tried if value is equal to and value includes.
Can any one see what is wrong with my comparison?
Solved! Go to the solution
This is an accepted solution.
Updated to one workflow.
Get Product (1) and (2) use query is checking for any product updated in the future. updated_at:>'{{ scheduledAt }}'
{% assign today_date = 'now' | date: "%Y-%m-%d"%}
{% for metafields_item in getProductDataForeachitem.metafields %}
{% if metafields_item.key == 'product_expiry_date' %}
{% assign expiry_date = metafields_item.value | date: "%Y-%m-%d" %}
{% if today_date == expiry_date %}
product_expired,
{% endif %}
{% endif %}
{% endfor %}
Hi,
Flow consumes and exposes the values from the shopify graphql admin api, and since the metafield value field is a string, it is treated as a string in Flow rather than a date. This is something we're investigating if we can add better support for, but currently isn't possible within Flow conditions.
To learn more visit the Shopify Help Center or the Community Blog.
Hi Steve, Thanks for the response. I did some further testing and have one more question.
I did some testing where I compared {% assign date_today = "now" | date: "%Y-%m-%d" | append: '' %}{{date_today}} to the string value "2023-10-17" and it returned true (testing for this was done in the CMS on the product page if that maters). Then I compared the metafield in Shopify flow to the string value "2023-10-17" it also returns true. However when I compare the metafield to {% assign date_today = "now" | date: "%Y-%m-%d" | append: '' %}{{date_today}} in Shopify flow it returns false. Which in theory should have converted the variable "date_today" to a string in the correct formatting as we can see from my first test.
So in Shopify flow {% assign date_today = "now" | date: "%Y-%m-%d" | append: '' %}{{date_today}} doesn't assign the variable "date_today" to a string? Sorry it's just not very clear why the comparison is invalid.
I would recommend outputting the values using "Log output". I'd suspect one of the values is not what you expect.
Hey, thanks I didn't know about the "Log output". I found out what the issue was, the code logic is correct. However the issue is that I can't inject liquid code in to the value field, is there any way I can use liquid code in the value field?
You cannot use liquid in conditions currently.
I am having the exact same issue as Troyn
how are you supposed to check if a date metafield is older than today in flow?
the available conditions also dont offer less than or greater than - only equal to 😕
any suggestions please?
You can only do that where liquid is available, which means you need to use it in an action. That may or may not work depending on your exact use case.
how about in the get order data part?
can you do something like this there?
i havent got it right obviously...
I am trying to find orders where the metafield custom.delivery_date has passed
This is what I'm currently looking into as well @FePixie, I'll let you know if I get any where with this approach.
I'm still not getting anywhere with flow 😞
i can do it with the admin REST api - but its such a cumbersome thing by the time you paginate requests and rate limit everything to a crawl because you have to ask so many times 😕 never mind having to host it elsewhere...
Do you have any suggestions for us @paul_n ?
I am trying to find orders where the metafield custom.delivery_date has passed
and @Troyn is trying to find products where the metafield product_expiry_date date has passed
hmm - i thought i might try checking externally - but a POST or GET does not seem to give me any output reply i can check? not even a response code?
on this page it looks like it should - am i missing something?
https://help.shopify.com/en/manual/shopify-flow/reference/actions/send-http-request
You need to build a task currently if you want return data (that feature was added to the CLI in summer editions)
Can you aim me at some docs about building a 'task' please? Not sure what you mean by that?
Docs on creating an action. https://shopify.dev/docs/apps/flow/actions
You cannot query by metafields yet - it's a limit of the API but would obviously be very useful for this kind of use case.
You could potentially do something like:
Order created -> Add order tag (with MF value...deliver_sep_21)
Then a second workflow:
Oh poop - That's gonna end up with a bunch of funny messy tags - and will make it very hard for my customer to filter anything in admin to see which ones need dates manually added. I'm reading a supplier spreadsheet via a script to add them to the metas with the rest api - i suppose i'm gonna need to write my own script for this part too 😕
can you add searching by metafields and liquid in filters to the flow wishlist please!
Searching by metafields isn't a Flow request - it's a request for the metafields people. Once it's there, you should be able to use it automatically in Flow.
But noted about liquid in conditions. We are looking at how to enable that (better support for code overall)
This seems to work @Troyn ...
putting code in the action as Paul said
here's my code in the add tag bit...
{% assign today_date = 'now' | date: '%s' %}
{% for metafields_item in getOrderDataForeachitem.metafields %}
{% if metafields_item.key == 'delivery_date' %}
{% assign pre_date = metafields_item.value | date: '%s' %}
{% if today_date > pre_date %}
OLDDATE,
{% else %}
Has ETA,
{% endif %}
{% endif %}
{% endfor %}
i hope something like that works for you on the products too 🙂
small refinement - i chucked out all the OLDDATE tags before going through and re-tagging - to remove the ones where the date has been changed.
i hope that saves someone the heap of hours i spent on it 🙂
Thanks for all the help @FePixie and @paul_n!
I was able to get it working. I ended up using 3 workflows. Here's a rundown if any one needs to do something similar in the future.
1) add a tag on a product if the metafield is equal to todays date runs at 00:00
{% assign today_date = 'now' | date: "%Y-%m-%d"%}
{% for metafields_item in getProductDataForeachitem.metafields %}
{% if metafields_item.key == 'product_expiry_date' %}
{% assign expiry_date = metafields_item.value | date: "%Y-%m-%d" %}
{% if today_date == expiry_date %}
product_expired,
{% endif %}
{% endif %}
{% endfor %}
2) archive the product with the added tag runs at 00:01
3) remove that tag from the product (allows for the product to be reactivated without workflow 2 archiving it again)
nice one 🙂
did it not play nice if you add the next flow under the 'Then' on the foreach step?
I didn't read the documentation completely so I missed the fact that the action occurs after each action. I'll correct the workflow now.
that'll help if the shopify end goes slow - i've seen it take more than 1 min when it's got a bellyache 👍
This is an accepted solution.
Updated to one workflow.
Get Product (1) and (2) use query is checking for any product updated in the future. updated_at:>'{{ scheduledAt }}'
{% assign today_date = 'now' | date: "%Y-%m-%d"%}
{% for metafields_item in getProductDataForeachitem.metafields %}
{% if metafields_item.key == 'product_expiry_date' %}
{% assign expiry_date = metafields_item.value | date: "%Y-%m-%d" %}
{% if today_date == expiry_date %}
product_expired,
{% endif %}
{% endif %}
{% endfor %}
This is great!
I believe this can be further simplified in the second column (get product data (1)) and the query can be set to updated_at:>'{{ scheduledAt }}' tag:"product_expired" and third column (get product data (2)) can be set to updated_at:>'{{ scheduledAt }}' tag:"product_expired" status:"archived"
hello, I am trying to follow the steps you are creating but when I try to run, it seems it is running but very slow and the end it disappear in my "recent runs"... i am not sure why.. and here is the steps
Do not use metafieldDefinitions. They are the schema for your metafields, not the metafields.
Do you have any successful or failed workflow runs? If so, please share one that didn't work as expected. If no, then you likely have an extreme inefficiency in the workflow somewhere. If that's true, post a sceenshot of your condition and any liquid code.
Flow just launched improved metafields support, which makes it much easier to access and use metafield data in Flow.
https://changelog.shopify.com/posts/shopify-flow-access-typed-metafields
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024