Help

Re: issue in Automation with condition process

Solved
Jump to Solution
2320 0
cancel
Showing results for 
Search instead for 
Did you mean: 
FraWork_85
5 - Automation Enthusiast
5 - Automation Enthusiast

Hello, 

in a automation on Airtable I set up a trigger that, when someone submit a form and create a record in a table named "customer", Airtable run a script that have a vlookup function that read a "Program code" value and insert the "Program Name" from "Code" table. If the vlookup have a correspondence than the value of the cell is equal to the "Program Name" if not the cells value is "Not found".

After this action I set up a script that wait 20 sec. in order to wait the update of the data in the record and then I put a condition that:

If the "Program Name" is "Not found" then send an email "Code not found"

Otherwise (and then it means that "Program Name" have the name of the program) then send another email with the landing page and other info. 

If I test manually this automation with the function "Test Automation" with a selected record  this action work correctly. But if I submit a form and this automation run with his trigger, the output is always the otherwise condition output. 

How it is possible? I see that before the condition start, the field on the inserted record is ready and it is "Not found". How it is possible that the automation not read "Not found"? 

 

Find attacched the structure of the automation. Many thanks! 

1 Solution

Accepted Solutions

Ah, yeah, if you don't have much coding experience let's just focus on the "Find Record" solution!

To do that, try this:
1. In your mainTable, add a new field with the formula "record_id()" and call it Record ID
2. In your automation, add a "Find Record" action right before the conditional, and its going to look for a record in mainTable that has the same Record ID as the triggering record
3. Update your conditional to check the value of the "Programma" field from the "Find Record" action

If you can DM me an invite to your base I can help you set it up real quick!

See Solution in Thread

8 Replies 8

Hmm, I take it you're updating the record via one of the scripts there, and then your condition uses that updated data? 

If so, that's because the conditional is checking on the record's data when the automation triggered, and not the current data.  You'll need to use a "Find Record" step to look for the record you updated, and then use that "Find Record" action's result in your conditional.  I think I would just use `output.set()` if I were you though, seems simpler

Hi Adam and thanks for your support! 

Now I understand... it means that the condition doesnt use the updated data of the record. Understand! 

What do you mean abot the use of the output.set() ? Need to use another script to force the condition to use the updated dateset? 

Let me know and thanks again! 

Ah, for the output.set thing, you know how you've got a script that's updating the record with the correct cell value?  Just add a new line for that, e.g. `output.set('programName', cellValue)`

This'll give you a variable that you can use in the later stages of your automation, so you can plug that into the conditional

FraWork_85
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi Adam and thanks again... 

find below the code that i wrote in order to update the cells of the column "Programma" with the value "Not found" in case of "Codice Programma" is not available in the list of the code in the table "Codici".

// Sostituisci "Orders" con il nome della tabella che contiene i valori su cui vuoi eseguire la funzione VLOOKUP
let mainTable = base.getTable("Clienti");
let mainTableRecords = await mainTable.selectRecordsAsync({ fields: ["Codice programma"] });

// Sostituisci "Product" con il nome della tabella che contiene l'intervallo di ricerca
let lookupTable = base.getTable("Codici");
let lookupRangeRecords = await lookupTable.selectRecordsAsync({ fields: ["Codice", "Programma"] });

// Sostituisci "Item.barcode" con il nome della colonna che contiene i valori da cercare
for (let record of mainTableRecords.records) {
    let lookupValue = record.getCellValue("Codice programma");
    let foundMatch = false;

    // Sostituisci "Barcode" con il nome della colonna che rappresenta l'intervallo di ricerca
    // Sostituisci "Name" con il nome della colonna il cui valore deve essere restituito
    for (let rangeRecord of lookupRangeRecords.records) {
        if (rangeRecord.getCellValue("Codice") === lookupValue) {
            let returnValue = rangeRecord.getCellValue("Programma");

            // Sostituisci "Proper Name" con il nome della colonna della tabella principale che dovrebbe contenere il collegamento
            await mainTable.updateRecordAsync(record, {
                "Programma": returnValue
            });

            foundMatch = true;
            break;
        }
    }

    if (!foundMatch) {
        // Se non viene trovata una corrispondenza, imposta "Not found" nella colonna "Programma"
        await mainTable.updateRecordAsync(record, {
            "Programma": "Not found"
        });
    }
}
output.set('Programma',"Not found")

 I put the output.set() line as you advise but when run the automation, the conditition that have to trigger with the value "Not found" doesn't start and go to the Otherwise condition as if he do not read "Not found" as a value. 

You'll need to use output.set within your `if`, so to set it when there's no found match you would put output.set inside the "if(!foundMatch)" like so:

 

 if (!foundMatch) {
        // Se non viene trovata una corrispondenza, imposta "Not found" nella colonna "Programma"
        await mainTable.updateRecordAsync(record, {
            "Programma": "Not found"
        });
        output.set('Programma',"Not found")
    }
}

 


If you don't have much programming experience, I would highly recommend you use the "Find Record" solution instead as it works fine though

 
FraWork_85
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi Adam and thanks again.

Yes I do not have much programming experience... sorry. I tried to copy and set up your code and it not work 😞

Below You find the code:

// Sostituisci "Orders" con il nome della tabella che contiene i valori su cui vuoi eseguire la funzione VLOOKUP
let mainTable = base.getTable("Clienti");
let mainTableRecords = await mainTable.selectRecordsAsync({ fields: ["Codice programma"] });

// Sostituisci "Product" con il nome della tabella che contiene l'intervallo di ricerca
let lookupTable = base.getTable("Codici");
let lookupRangeRecords = await lookupTable.selectRecordsAsync({ fields: ["Codice", "Programma"] });

// Sostituisci "Item.barcode" con il nome della colonna che contiene i valori da cercare
for (let record of mainTableRecords.records) {
    let lookupValue = record.getCellValue("Codice programma");
    let foundMatch = false;

    // Sostituisci "Barcode" con il nome della colonna che rappresenta l'intervallo di ricerca
    // Sostituisci "Name" con il nome della colonna il cui valore deve essere restituito
    for (let rangeRecord of lookupRangeRecords.records) {
        if (rangeRecord.getCellValue("Codice") === lookupValue) {
            let returnValue = rangeRecord.getCellValue("Programma");

            // Sostituisci "Proper Name" con il nome della colonna della tabella principale che dovrebbe contenere il collegamento
            await mainTable.updateRecordAsync(record, {
                "Programma": returnValue
            });

            foundMatch = true;
            break;
        }
    }

    if (!foundMatch) {
        // Se non viene trovata una corrispondenza, imposta "Not found" nella colonna "Programma"
        await mainTable.updateRecordAsync(record, {
            "Programma": "Not found"
        });
        output.set('Programma',"Not found")
    }
}

How I can use the "Find Record" solution? 

Let me know. Thanks! 

Ah, yeah, if you don't have much coding experience let's just focus on the "Find Record" solution!

To do that, try this:
1. In your mainTable, add a new field with the formula "record_id()" and call it Record ID
2. In your automation, add a "Find Record" action right before the conditional, and its going to look for a record in mainTable that has the same Record ID as the triggering record
3. Update your conditional to check the value of the "Programma" field from the "Find Record" action

If you can DM me an invite to your base I can help you set it up real quick!

FraWork_85
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi Adam, 

thank you so much for your solution! It work very well! 

I used the Find record action that track and update the record and use it for the condition in the automation! Thank You!!