Feb 29, 2024 12:14 AM - edited Feb 29, 2024 12:24 AM
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!
Solved! Go to Solution.
Mar 05, 2024 02:06 AM
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!
Feb 29, 2024 01:42 AM
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
Feb 29, 2024 06:30 AM
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!
Feb 29, 2024 07:57 PM
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
Mar 01, 2024 01:23 AM
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.
Mar 01, 2024 02:42 AM
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
Mar 04, 2024 06:19 AM
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!
Mar 05, 2024 02:06 AM
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!
Mar 07, 2024 08:28 AM
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!!