Help

Re: Automation run the limit

1278 0
cancel
Showing results for 
Search instead for 
Did you mean: 
PauloPurcino
6 - Interface Innovator
6 - Interface Innovator

 My automation exceeded the run limit 2500 in just a few hours because I don't know how to control it! Can someone help me?

c7e9adb1-7ae6-4203-9b22-0665a0bf086c.jpeg

8bc3071c-b99f-426f-9365-4fbe2be8ba01.jpeg

IMG_3369.jpeg

13 Replies 13
PauloPurcino
6 - Interface Innovator
6 - Interface Innovator

This table is a form that, when my user fills it out, automates distance data between two points using the Haversine formula and also automates the conversion of latitude and longitude using the Google Maps reverse geocode API. The problem is that when my user enters their information, in addition to the perfect response from my script, it is generating unnecessary blank lines and using all of my runs.

Hello @PauloPurcino 

I think your Automation scripts are overlapping as @ScottWorld  mentioned above. For now, just disable automation and verify it properly until it's fixed.

Please write your code(with removed credentials). Then some community members verify it.

Also, let me know that does you generate JS code using any AI Model(GPT, Bard, etc), Or if it's created by any specialist.

Yes ,I generated JS by AI.

SCRIPT 1:

 

 

let table = base.getTable("Table 2"); // Substitua "SuaTabela" pelo nome da sua tabela

let records = await table.selectRecordsAsync();

for (let record of records.records) {
    let lat1 = record.getCellValue("latitude1");
    let lon1 = record.getCellValue("longitude1");
    let lat2 = record.getCellValue("latitude2");
    let lon2 = record.getCellValue("longitude2");

    if (lat1 !== null && lon1 !== null && lat2 !== null && lon2 !== null) {
        let distance = getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2);

        // Atualize o valor da coluna "distance" com a distância calculada
        await table.updateRecordAsync(record, {
            "Distance": distance
        });
    }
}

// Função para calcular a distância entre dois pontos em coordenadas de latitude e longitude
function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) {
    const R = 6371; // Raio da Terra em quilômetros
    const dLat = deg2rad(lat2 - lat1);
    const dLon = deg2rad(lon2 - lon1);

    const a =
        Math.sin(dLat / 2) * Math.sin(dLat / 2) +
        Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
        Math.sin(dLon / 2) * Math.sin(dLon / 2);

    const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    const distance = R * c; // Distância em quilômetros

    return distance;
}

// Função para converter graus em radianos
function deg2rad(deg) {
    return deg * (Math.PI / 180);
}
------------------------------------------
SCRIPT 2
 
let table = base.getTable("Table 2"); // Substitua "SuaTabela" pelo nome da sua tabela
let apiKey = "MY API KEY"; // Substitua "SuaChaveAPI" pela sua chave de API do Google Maps

let records = await table.selectRecordsAsync();

for (let record of records.records) {
    let lat = record.getCellValue("latitude1");
    let lon = record.getCellValue("longitude1");

    if (lat !== null && lon !== null) {
        let address = await getReverseGeocoding(lat, lon, apiKey);

        // Atualize o valor da coluna "endereco" com o endereço retornado
        await table.updateRecordAsync(record, {
            "endereco": address
        });
    }
}

// Função para realizar Geocodificação Reversa usando a API do Google Maps
async function getReverseGeocoding(latitude, longitude, apiKey) {
    let apiUrl = `https://maps.googleapis.com/maps/api/geocode/json?latlng=${latitude},${longitude}&key=${apiKey}`;

    let response = await fetch(apiUrl);
    let data = await response.json();

    if (response.ok && data.results.length > 0) {
        return data.results[0].formatted_address;
    } else {
        console.error("Erro ao obter o endereço:", data.error_message || "Erro desconhecido");
        return null;
    }
}

Hello @PauloPurcino 

Both of the scripts are only doing updateRecordAsync (https://airtable.com/developers/scripting/api/table#update-record-async)

To trigger your automation which is called when a new row is created script needs to call this (https://airtable.com/developers/scripting/api/table#create-record-async)

Cross-check all other Airtable automation and also check external process automation tools(Zapier, Make.com). If there is anything that causes this issue.