- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Aug 11, 2019 10:43 PM
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
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Aug 13, 2019 01:46 AM
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] + "')";
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Aug 13, 2019 01:46 AM
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] + "')";