Flow Add Order Line Item Dynamic Quantity?

I’m working on a back end process through the Flow app to add an item to customer’s orders when they purchase certain items. I’ve successfully created the Flow but an I need help with an issue. I want to be able to add a quantity based upon how much of a certain item is ordered.

For example, if a customer purchases two of product x then I want the flow to add two of product y. Currently the flow sees the purchase of product x but only assigns one, as is indicated in the flow.

Current flow path is the following:

  1. Trigger: Order created
  2. Check if: item is on order
  3. Then action: add order line item
  4. Then action: add order tag

I couldn’t find anything about being able to add dynamic scripting in the add order line item quantity field. Any help would be appreciated!

You can now change this value using Liquid. Make sure your code always outputs a number!

Hi, i have been strugeling with this issue also and i could not manage to use your solution. But now with “write Code” it was very easy

This was the setup

Then by addin “run Code” i could take the quantity of the spesific SKU as a variable in the “add order line”

input

{
order {
lineItems {
sku
quantity
}
}
}

Output

type Output {
totalQuantity: Int!
}

Write code

export default function main(input) {
let totalQuantity = 0;
input.order.lineItems.forEach(item => {
if (item.sku === ‘90009’) {
totalQuantity += item.quantity;
}
});
return {
totalQuantity: totalQuantity,
};
}

And here is the add order line

Worked like a charm

1 Like