-1
I’m creating an agent in Dialogflow and using Airtable as BD.
Everything is working well, I’m able to access the comic and bring the results.
But I can’t "throw the result out" of the function and access it at the end to print.
Follows code:
function showSinglePrice(agent) {
var finalPrice;
var arraySinglePrice = null;
const item = agent.context.get("item"),
place = item.parameters.place,
size = item.parameters.size,
type = item.parameters.type;
base(tablePizzas)
.select({
maxRecords: 10, //
view: viewName,
filterByFormula: `AND({type} = "${type}",{size} = "${size}",{place} = "${place}")`
})
.firstPage(function(error, records) {
if (error) {
response.send({ error: error });
} else {
arraySinglePrice = records.map(record => {
return {
price: record.get("price")
};
});
console.log(arraySinglePrice); //isso funfa
var finalPrice = arraySinglePrice[0].price; //isso tb
return finalPrice;
}
});
agent.add(`Valor deveria vir aqui: ${finalPrice}`); //não chega aqui
}
Always gives Undefined.
I’ve tried a lot of things, but I’m stuck.
Some help?
your remark is correct. thanks for pointing. fixed now. Still the problem persists. The method I am using . select(). firstpage() comes from a library called airtable.js| This method returns a precedent. So I know in theory that the JS is "advancing", trying to print at the end before the method ends. But I don’t know how to do the STOP code, wait for the end of the call before.
– vpego