Dear Airtable Community,
im working on an automization to assign volunteers to specific working shifts according to their preferences. The volunteers can name socalled Besties to work with, so the code has to first assign matching volunteers into Bestie Groups and afterwards assign the whole group to a preferred shift. The code worked until I started "optimizing" the runtime of the code and creating a volunteerMap at the beginning of the code to have it set and not need to map it during the analyzation of the volunteers besties. (Hope that is understandable until here)
After implementing my async function refreshVolunteerMap the following error occured:
async function refreshVolunteerMap() {
try {
if (!volunteerMap || volunteerMap.size === 0) {
logMessage("Refreshing volunteer map...", LOG_LEVELS.INFO);
// Specify the fields to fetch
let fieldsToFetch = ["Volunteer Name", "Assigned Shifts", "Bestie"];
let volunteerRecords = await volunteersTable.selectRecordsAsync({ fields: fieldsToFetch });
logMessage(`Fetched ${volunteerRecords.records.length} records from volunteersTable.`, LOG_LEVELS.DEBUG);
volunteerMap = new Map(); // Initialize or reset the map
for (let record of volunteerRecords.records) {
let volunteerName = record.getCellValue("Volunteer Name");
logMessage(`Processing record ID: ${record.id}, Name: ${volunteerName}`, LOG_LEVELS.DEBUG);
let normalizedName = normalizeName(volunteerName);
if (normalizedName) {
volunteerMap.set(normalizedName, record);
logMessage(`Mapped "${volunteerName}" -> "${normalizedName}"`, LOG_LEVELS.DEBUG);
} else {
logMessage(`Skipping record ID: ${record.id} due to invalid name.`, LOG_LEVELS.ERROR);
}
}
logMessage(`Volunteer map refreshed with ${volunteerMap.size} entries.`, LOG_LEVELS.INFO);
} else {
logMessage("Volunteer map already initialized, skipping re-fetch.", LOG_LEVELS.INFO);
}
} catch (error) {
logMessage(`Error in refreshVolunteerMap: ${error.message}`, LOG_LEVELS.ERROR);
throw new Error(`Failed to refresh volunteer map: ${error.message}`);
}
}
and my Main execution (Line 837 is await refreshVolunteerMap()) at the end of the Code looks like this:
await refreshShiftsData();
await refreshVolunteerMap();
let pendingRecord = await fetchNextInQueue();
setLogLevel(LOG_LEVELS.INFO); // For standard runs
//setLogLevel(LOG_LEVELS.DEBUG); // During debugging
//setLogLevel(LOG_LEVELS.ERROR); // Only show errors
if (pendingRecord) {
let volunteerLink = pendingRecord.getCellValue("Volunteer ID");
let volunteerId = volunteerLink?.[0]?.id;
if (volunteerId) {
let volunteerRecord = await volunteersTable.selectRecordAsync(volunteerId);
logMessage(`Processing volunteer: ${volunteerRecord.getCellValue("Volunteer Name")}`, LOG_LEVELS.INFO);
let bestieGroupsMap = await precomputeBestieGroupsMap();
await assignShiftsToVolunteer(volunteerRecord, pendingRecord.getCellValue("Autonumber"), bestieGroupsMap);
await updateQueueStatus(pendingRecord.id, "Completed");
} else {
logMessage(`No valid linked volunteer for pending record.`, LOG_LEVELS.INFO);
}
}
I also read about restrictions in fetching records, but the error says something different in my opinion.
https://support.airtable.com/docs/run-a-script-action#run-a-script-action-limits
Maybe you have any good idea.
Thanks in advance and wish you all a happy start into 2025!
Mogli
_hobby programmer doing fun projects_