https://discord.gg/botpress logo
Use variable as single choice items
# 🤝help
a
Hi community. I need your help here. I have a variable that contains and array of items. I want to display a field "nombre" of each of the items so the user is able to select one of them. I'm using a single choice card, placing the array variable as items, but I'm getting "Error executing card "card:capture" in flow:Vale de compra:node:Standard11 - TypeError: Cannot read properties of undefined (reading 'length')" https://cdn.discordapp.com/attachments/1381586346283372565/1381586346447208518/image.png?ex=684c028d&is=684ab10d&hm=42a459cf1118cefd34f851f26a1ef2ec17801e35e3d7084eb9c6f611e53f3bf7& https://cdn.discordapp.com/attachments/1381586346283372565/1381586346711187596/image.png?ex=684c028d&is=684ab10d&hm=3b279703d45129ba06bf9cc7fdabed482920c0decbffc2477e7e59f1d99cefa9&
p
Have you tried expressing the whole path within the items field?
b
Hi! I think the issue comes from the structure of your array. The Single Choice card in Botpress expects an array of objects where each item has at least a label and a value property. If your array only has a nombre field, you’ll need to map it to the expected format. You should do something like this: array.map(item => ({ label: item.nombre, value: item.nombre })) Then use that new array as the items source for your card. Let me know if that helps!
a
Yep @broad-knife-66298, that's exactly what I needed, and it worked like a charm