When Searching for Values from the Database, Code ...
# 🤝help
s
Hello BotBuilders, as the title says, I want to enter a value (the username), and search the values linked to that row, but my bot only gives a successful answer when im trying the first record. I didn't have this problem in the past, any ideas of what I may be doing wrong?
f
Hey there Maybe you could share the way you are doing it right now
basically the user inputs his username and a code changes it into a mail because i saw the tutorial from robert in botpress (i think), and the find records box only works with mail so you can say I "parsed it", and it works, but only for the first record, the others dont apply
im using instead this code: but now everytime {{existingUser}} value is 1, even if the user.nom variable is not existing in the Table https://cdn.discordapp.com/attachments/1244506112166989824/1244742342611832943/image.png?ex=66563824&is=6654e6a4&hm=08789eff7f233b4afc68a36549cc5a94105221b8bd4f922aef8ee572d277ad90&
its (records.length > 0 ? 1 : 0 )) btw
f
Its probably with the way you are using the
.then
method. Lets try with some better error handling with a try/catch block and with a correct condition so it sets
existingUse
to 1 if the user exist and else 0
Copy code
javascript
const userNom = user.nom;

try {
    const records = await CuentasTable.findRecords({
        filter: {
            username: userNom
        }
    });

    const existingUser = records.length > 0 ? 1 : 0;
    workflow.existingUser = existingUser;

} catch (error) {
    console.error("Error fetching records:", error);
    workflow.existingUser = 0;
}
Let me know how it goes
s
nope thats not it, same error as before, it only recognizes the first 2 usernames in the table
27 Views