#Help Needed: Cumulative Item Calculation Issue in Bot Development
1 messages · Page 1 of 1 (latest)
Create and publish conversational forms that collect 4 times more answers and feel native to your product
Let me know if you can see the first time I share.
I greatly appreciate it, if you could create a mini example. I've learned a lot from the default templates in Typebot, but I couldn't find any reference for what I need.
@indigo socket
it's a bit difficult for me to understand the exact flow, as your bot is in Portugese, and my browser is not really converting it to English
could you instead share the logic/block, where you are adding the new item to the existing list/order?
maybe there's an issue there

const selectedItem = {{Get_menu_item}};
const selectedQuantity = {{input_quantity}};
const orderJSON = { "items": [], "total": 0 };
// Replace this block with the actual code to find the item in arrItems
const objItem = arrItems.find(item => item === selectedItem);
const price = objItem ? 5 : 0; // Replace 5 with the actual item price
const orderObj = JSON.parse(JSON.stringify(orderJSON));
const newItem = { item: selectedItem, qty: selectedQuantity, unitPrice: price };
orderObj.items.push(newItem);
const total = orderObj.items.reduce((acc, item) => acc + item.unitPrice * item.qty, 0);
orderObj.total = total;
return total;```
I just wish I could include cumulative items like a shopping cart.
@indigo socket
i'm unable to look into this in more detail right now
but so far, it seems that the logic is broadly correct
i'd recommend doing console.log at multiple steps, to find out how the flow is actually getting executed
Is the logic of adding the item to the cart simply to return the flow to the menu again?
Anyway, I'll wait; I'll keep researching. Any simple examples are welcome for persisting the items on the order ticket.
@polar python ty ❤️
@polar python In this template, the issue becomes more isolated for you to better understand.
check this out: https://app.typebot.io/typebots/clrcfh7sd001v7swj1yxnj1l2/edit
should make sense
Thank you for helping.
I don't know why it's not working.
if you are worried about the error, it is because of emojis as JSON.parse is failing when parsing emojis
try removing the emojis and it should work
you can always execute on client and check your browser console log to know what is failing
It's not possible, haha. I'll remove the emojis and test.
I removed the emojis and the error still persists. 
@terse totem
May I know what exactly is the issue?
😅 can not seem to understand much what exactly you want to do
if u can explain via video that'd be perfect
I am not fluent in English, I will edit a photo as I would like it to work because it is showing an error.
This is what I wished to accomplish. First, I selected the large pizza with a quantity of 1. Then, I added 2 medium pizzas, and the total was being calculated cumulatively. In the end, the formatted order was delivered to me with the items.
Sorry for not explaining better. It's because I'm not fluent in English. Explaining via video would be easier.
dmed you
this seems to be working fine or is this what you want to achieve but can not?
This is what I desire, but I'm having trouble implementing it. What you sent is also throwing an error, but it's in this logic.