I am trying to get my record from airtable using async await. What i want is that once airtable has fetched all the records it should return a value 1 which will be assigned to a variable counter. Once value of counter is 1 it can be used to access other data as well. The problem is that since airtable api has a record limit of 1. Even before it reaches all the elements it sets the value of counter to 1. I know this is weird because page function should be called in airtable api before done function unless it has traversed across all the records. Here is my code :
var counter = 0;
async function FirstCall(){
counter = await backlinksubmissionChecker.getData();
console.log("Counter value is ",counter);
if(counter==1){
counter = await codequalityXP.getData();
console.log("Counter value is ",counter);
}
}
my code for airtable api access is like this
async function getData()
{
return new Promise((resolve, reject) => {
console.log("Inside Backlink submission checker");
var i=0;
let value = base("Program XP").select({
}).eachPage(function page(records, fetchNextPage) {
records.forEach(function(record) {
let recordID = record.get("RecordID");
let email = record.get("Email Address");
ConnectStudents(recordID,email);
i++;
});
fetchNextPage();
}, function done(err) {
if (err) {
console.error(err);
reject("Promise rejected");
}else{
resolve(1);
}
});
});
}
How do I ensure that my airtable api has brought me all the records before it sends a resolve promise which tells that it has traversed through all records.