Goal: Build a Shopify Flow automation that, on order creation, checks if the new order has certain SKUs (stock keeping units) and then inspects only the customer’s previous orders for specified SKUs, excluding the current order.
Current issue: The query appears to include the triggering order among “previous” orders.
Proposed approach: Use a Get order data action with an advanced query that filters by customer_id and a created_at timestamp set to earlier than the current order (e.g., created_at <= order.createdAt minus 1 minute) to return only earlier orders.
Checking for SKUs: Add a query argument like SKU:somesku. Reference: Shopify Admin GraphQL Orders query arguments.
Open questions: Whether sorting is needed to always identify the immediately previous order remains unclear; a screenshot was shared but no definitive setting provided.
Additional guidance: A race condition may sometimes return the current order. Mitigation: In the downstream For Each loop, skip any order whose ID equals the triggering order’s ID.
Status: No confirmed resolution. Recommended path is the time-bounded query plus an explicit ID check to exclude the current order; sorting specifics are not finalized.
I am trying to run a work flow that is triggered when an order is created with a condition that checks if the order contains one of a set range of SKUs/products, if true, I would then like the condition to check the customers PREVIOUS orders (not including the order that triggered the flow) for any of a set range of products/SKUs.
I thought this was working but it seems to be looking at all of the customers orders, including the order that triggered the flow.
Do we need to sort the orders that are fetched, and if so, what’s the right setting to always get the previous order? Thought we had it solved, but clearly not working yet
What does “clearly not working” mean? Can you describe what you are observing?
Assuming you mean that it sometimes returns the current order, you could have a race condition here. Another approach could be to not worry about returning the current order in the query. Instead, add a condition in the downstream “For Each” loop to check if the returned order ID = order.id