My code is as follows, but line 4 seems to throw an error. Any suggestions on how to use the filterbyFormula?
function checkmerchant(merchant) {
let table = base.getTable(“Imported table”);
for (let field of table.fields) {
let recordFound = table.select({
filterbyFormula: REGEX_MATCH({${field.name}},"${merchant}")
})
console.log(recordFoundo0]);
}
}
checkmerchant(‘MAKEMYTRIP’);
My code is as follows, but line 4 seems to throw an error. Any suggestions on how to use the filterbyFormula?
function checkmerchant(merchant) {
let table = base.getTable(“Imported table”);
for (let field of table.fields) {
let recordFound = table.select({
filterbyFormula: REGEX_MATCH({${field.name}},"${merchant}")
})
console.log(recordFoundo0]);
}
}
checkmerchant(‘MAKEMYTRIP’);
The formula that you’re using assumes that all of the queried fields will return strings (REGEX_MATCH()
requires a string as its first argument). If any of those fields returns an array, that could be the cause of the error. What are the field types that you’re querying?
The formula that you’re using assumes that all of the queried fields will return strings (REGEX_MATCH()
requires a string as its first argument). If any of those fields returns an array, that could be the cause of the error. What are the field types that you’re querying?
@Justin_Barrett thanks for the response!
I was trying this code on Airtable Scripting and I think I read somewhere that Scripting doesn’t support filterbyformula. However, I was able to run this on node js with a few minor changes to the code as below.
Separately, I am looking for the tool to just output the matched keyword and not the full record? What change to recordse0] would I need to implement? thank you
function checkAirtableId(merchant) {
let tabletest = base(‘Imported table’);
for (let i = 1; i < 15; i++) {
let y = ‘Field’ + ’ ’ +i;
let recordFound = base(‘Imported table’).select({
filterByFormula: REGEX_MATCH({${y}},"${merchant}")
}).firstPage(function(err,records) {
if(err) {
console.log(err);
return;
}
console.log(records/0]);
})
}}
@Justin_Barrett thanks for the response!
I was trying this code on Airtable Scripting and I think I read somewhere that Scripting doesn’t support filterbyformula. However, I was able to run this on node js with a few minor changes to the code as below.
Separately, I am looking for the tool to just output the matched keyword and not the full record? What change to recordsd0] would I need to implement? thank you
function checkAirtableId(merchant) {
let tabletest = base(‘Imported table’);
for (let i = 1; i < 15; i++) {
let y = ‘Field’ + ’ ’ +i;
let recordFound = base(‘Imported table’).select({
filterByFormula: REGEX_MATCH({${y}},"${merchant}")
}).firstPage(function(err,records) {
if(err) {
console.log(err);
return;
}
console.log(recordso0]);
})
}}
Correct. The API for Airtable’s Scripting app is not the same as the API used when querying Airtable from an outside server. They use completely different ways of retrieving and interacting with the data. The proper way to filter records inside of Airtable’s scripts is to collect the records first using selectRecordsAsync
, then filter the results using JavaScript’s normal .filter
method. The Scripting app API docs are available at the bottom of the Scripting app interface.
Regarding your second question, it’s not just a matter of changing recordse0]
. There are numerous things in your script design that don’t follow the proper methods of accessing Airtable data from within the Scripting app. The app’s API is documented at the bottom of the app interface. I suggest taking some time to read through it and familiarize yourself with the differences, then rewrite your script.