I’m hoping somebody here knows how to write a custom query to pull an integer value from a custom metafield.
I have created a custom, product variant metafield called Reorder threshold. Reorder threshold is an integer field. Its key and namespace are “custom.reorder_threshold”.
I’m trying to make a workflow that does the following:
When a product variant’s inventory count is updated, check if the new inventory count is less than or equal to the product variant’s reorder threshold. If it is, then create a task in Asana. Otherwise, do nothing.
The way I intend to do this is with the Get product data action and a custom query to pull the product variant’s reorder threshold; then I could reference that data as a variable in a subsequent “Check if” block. The only problem is, I don’t know how to write the custom query to do that…
Has anyone tried to do something similar and have a query I could reference?
If any part of my inquiry does not make sense, please let me know, and I will rephrase. Any help would be very much appreciated!
Why do you need to use Get product data at all? You have access to a product, product variant, and all their metafields from the inventory quantity changed trigger, since it provides both a product ID and a variant ID.
I looked for ways to do it without using Get Product Data. Slides #1 - 2 of the attached pptx shows how I planned to do it initially. The problem is in the Condition block, when I click the <> icon to select a Trigger Variable, there is no option for metafields under Product or Product Variable. I even tried searching for it (see slide #3 of attachment.pptx).
When I wrote in to support about it, they said, “I checked with our Internal team and I can confirm that creating a condition in the Flow that triggers the Product metafields is not currently supported. This is something that our developers are aware of, however I am unable to guarantee if this will be implemented in the future.”
This leads me to believe I must use Get Product Data. What do you think?
Ah, I see. You want to compare a quantity from the trigger with a metafield value. It’s doesn’t work yet in a condition as support said. The main issue is metafields return strings and the trigger provides a number, so the editor doesn’t allow them to be used together.
you can compare the values in liquid (the asana task) but that would mean that action always gets called.
I can’t think of a great way around this right now. One hack would be to write the liquid to set a tag or metafield and then immediately check that value in a condition. The workflow would look like:
trigger
add product tag with liquid code. For example, you might add a “time to reorder” tag.
wait step of 10s - this causes flow to fetch data after the step (the tag you just added)
Is this true even when the Content type of a metafield is set to Integer? If Content type is only for data validation, and metafield data is always read in as a string regardless of Content type, then I think that puts the nail in the coffin of this workflow. Is it possible to typecast within a custom query?
About your proposed hack, I may be misunderstanding, but I don’t think it would work either. Unless there is a way to conditionally apply the tag based on a metafield value, then the tag would always be applied and the subsequent action would always be called.
Once they are in liquid, everything is a string. And metafields are basically all strings. But the condition isn’t liquid, so that’s the mismatch.
I’m pretty sure the tag idea will work. If the liquid returns nothing, it just won’t add a tag. And you can put liquid in a tag field (be sure it hit enter and it save the code somewhere as it’s hard to edit there).