To have this apply only to the 2nd and 3rd orders apply these changes:
Here we proceed with the comparison only if the number of orders is 2 or 3 otherwise we return followUp is false
Write Code
export default function main(input) {
const orders = input.getOrderData;
// Check if the number of orders is 2 or 3
if (orders.length === 2 || orders.length === 3) {
// Parse the current and previous orders' subtotal amounts as floats
const currentOrderAmount = parseFloat(orders[0].currentSubtotalPriceSet.shopMoney.amount);
const previousOrderAmount = parseFloat(orders[1].currentSubtotalPriceSet.shopMoney.amount);
console.log(orders);
// Check the conditions and return the appropriate object
const followUp = currentOrderAmount < 728 && previousOrderAmount > 728;
return {
followUp
};
} else {
return {
followUp: false
};
}
}
