Help

Upcoming database upgrades. Airtable functionality will be reduced for ~15 minutes at 06:00 UTC on Feb. 4 / 10:00 pm PT on Feb. 3. Learn more here

Variable in filterByFormula

Topic Labels: API
2605 2
cancel
Showing results for 
Search instead for 
Did you mean: 

Hi

Does anyone know if there is a way to filter with a variable in the filterByFormula function through the API? Getting this to work would allow me to fetch information from a specific e-mail, and display records from airtable dependent on that.

So, do this:

var filterstring = ‘shipment_name’;
base(‘Shipments’).select({
filterByFormula: Name=filterstring,
}).eachPage(function page(records, fetchNextPage) {

Instead of this:

base(‘Shipments’).select({
filterByFormula: ‘Name=“shipment_name”’,
}).eachPage(function page(records, fetchNextPage) {

I’m able to use a string-variable for the find method, but as far as I can tell that only allows me to find on the clunky recordname.

var recordname = ‘recDegFvWIgCSAlzg’;
base(‘Shipments’).find(recordname, function(err, record) {

Apologies in advance if this is a basic question, it’s my first attempt at developing anything with html/js/jquery.

Mads

2 Replies 2

Update:
figured out that I could use variables in filterByFormula if I set the entire filter as a variable. So instead of the first suggestion do this:

var filter = “({Name} = '” + shipment_name + “’)”;
base(‘Shipments’).select({
filterByFormula: filter
}).eachPage(function page(records, fetchNextPage) {

I’m baffled as to why this didn’t appear the previous few days I’ve been searching for it but, regardless, thank you so much. Worked perfectly.

(Apologies for bumping an old thread but maybe it’ll help others to reanimate it…)