Help

filterByFormula Syntax using the OR logic in Node.js

Topic Labels: API
Solved
Jump to Solution
3766 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Mike_Kramer
4 - Data Explorer
4 - Data Explorer

Hi,
I am new to Airtable and am trying to build a query that will act like a global search across multiple columns.

Our members table has the following columns {‘Full Name’,‘Phone’,‘Email’} that I would like to search.

I want to have a single search field on our site to look up members by either their Full Name, Phone, or Email.

This is the query that I am using, but it doesn’t work, and I have tried many incantations to no avail…

record = await table.select({
filterByFormula: OR(‘Full Name’=searchString, ‘Phone’=searchString, ‘Email’=searchString),
fields: [‘Member’, ‘Full Name’, ‘Phone’, ‘Email’, ‘Status’, ‘Member Photo’]
}).firstPage().then((records) => {
rec = records[0][“fields”];
return rec;
}).catch((err)=>{
console.error(err)
});

The above code works great if I use a simple filterByFormula such as:
filterByFormula: 'Member=' + member_id

Thanks in advance for any assistance!!

Mike

1 Solution

Accepted Solutions
Mike_Kramer
4 - Data Explorer
4 - Data Explorer

I figured this out myself. Here is the filterByFormula JS code I used to make a nested AND inside of an OR in case someone else can find it useful:

//Get the query parameter
var searchString = new String(ctx.query["search"]);//Get the Search Query string
//console.log("ctx.query['search'] =", JSON.stringify(searchString));

//Make an array of the input parameters
var firstLast = searchString.trim().split(" ");
//filterByFormula to search for Full Name, Email, Phone
var filterByFormula = "OR(AND({First Name}='" + firstLast[0] + "', {Last Name}='" + firstLast[1] + "'), {Email}='" + firstLast[0] + "', {Phone}='" + firstLast[0] + "')";

See Solution in Thread

1 Reply 1
Mike_Kramer
4 - Data Explorer
4 - Data Explorer

I figured this out myself. Here is the filterByFormula JS code I used to make a nested AND inside of an OR in case someone else can find it useful:

//Get the query parameter
var searchString = new String(ctx.query["search"]);//Get the Search Query string
//console.log("ctx.query['search'] =", JSON.stringify(searchString));

//Make an array of the input parameters
var firstLast = searchString.trim().split(" ");
//filterByFormula to search for Full Name, Email, Phone
var filterByFormula = "OR(AND({First Name}='" + firstLast[0] + "', {Last Name}='" + firstLast[1] + "'), {Email}='" + firstLast[0] + "', {Phone}='" + firstLast[0] + "')";