I’m certain this is a lack of understanding of JS or synchronous/asynchronous operations on my part, but: if I want to call Airtable.base.create through the Node.js module and actually get the created records (or error) returned to be used elsewhere, how would I do that?
I can get the information logged to console just fine, but I’m not clear on how to properly return it or assign it to a variable and use it elsewhere.
Best answer by Vital_Cell
Hi @Vital_Cell, how about you declare a variable above your function and store record ids there? As you’re passing the record anyways, you could declare an empty array and push record ids (or the entire record) into that array.
Then you’re able to reference those later on. Code could looks like this:
const records = [];
async function createRecord(record) {
...
records.push(record)
}
So I asked elsewhere and it seems the real problem was the asynchronicity, not the variable scope. Having a variable above the function would still just give me an array of unresolved Promise objects.
Hi @Vital_Cell, how about you declare a variable above your function and store record ids there? As you’re passing the record anyways, you could declare an empty array and push record ids (or the entire record) into that array.
Then you’re able to reference those later on. Code could looks like this:
const records = [];
async function createRecord(record) {
...
records.push(record)
}
Hi @Vital_Cell, how about you declare a variable above your function and store record ids there? As you’re passing the record anyways, you could declare an empty array and push record ids (or the entire record) into that array.
Then you’re able to reference those later on. Code could looks like this:
const records = [];
async function createRecord(record) {
...
records.push(record)
}
So I asked elsewhere and it seems the real problem was the asynchronicity, not the variable scope. Having a variable above the function would still just give me an array of unresolved Promise objects.