Schedule workflow on a list skips elements

I have API workflow which makes changes to element “Product” (updates field “StockQuantity”).
And I use it in “Schedule workflow on a list” when I need to update several Products within an order.
But if my Order have several identical products, then Workflow on a list sometime skips them. It updates only one.
Seems like it tries to update all items at the same time, which causes a bug.

I think that since in a products database, each product has a unique ID; when updating qty the workflow applies the action to each unique product it recognizes, so when it encounters it again, it knows that it has already been updated and skips it.
you can fix that by including each product once in the order and add a qty field to each order_item. this way you can simply reduce product stock by order item’s qty and not miss anything.
hope this helps.

1 Like

Action name is “Schedule workflow on a list” and not “Schedule workflow on unique elements”, so it should work in case of repeating things. Another thing is that sometimes it works and sometimes it skips, so when it is not predictable, it is really hard to trust an action.
And approach with qty of order_item would work if I don’t need to run the workflow on a list of orders, which might contain same items.

Right now, I found a workaround with Grouping a list of products and running a workflow on a list of groupings, but it is not very “light” in terms of workloads.

yes, a list of products which exist uniquely in the DB. but as long as you made it work. good for you.