Help

The Community will be temporarily unavailable starting on Friday February 28. We’ll be back as soon as we can! To learn more, check out our Announcements blog post.

FilterByFormula with a variable

Topic Labels: API
1154 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Ben_Peleg
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi community.

I’m very new to JS so apologies if this seems basic :pray: .

I’m using Twilio Functions (node.js) to load to AirTable all incoming texts. I’m utilizing 2 tables -

  • “Receive Text” with columns Text date, Text Body and UID.
  • “Users” with columns UID and Phone Number (and a bunch of others).

When a text comes in, I’m trying to use FilterByFormula with the phone number to retrieve the user’s UID from the “Users” table.

Here’s the code I’m running -

var filter = "({Phone Number} = '" + event.From + "')";
base('Users').select({
    filterByFormula: filter
}).eachPage(function page(records, fetchNextPage) {
    records.forEach(function(record) {
        console.log('Retrieved ', record.get('UID'));
        alert('Retrieved ', record.get('UID'));
    });
    fetchNextPage();
}, function done(error) {
    console.log(error);
});

let message = {
    "UID" : record.get('UID'),
    "Phone Number" : format_phone,
    "Inbound Text Date" : Date.now(),
    "Inbound Text Content" : event.Body
};

base('Receive Text').create(message, function(err, record) {
  if (err) { console.error(err); return; }
  console.log(record.getId());
  callback(null, message);
});

};

Last note - Without the “UID” in the message, the message uploads just fine.

My questions are -

  1. Both the UID and Phone Number are unique values in “Users”, so I’m not sure if I even need the whole piece on handling multiple records. Is there maybe a simpler way of doing it?
  2. I’m not sure I understand how exactly I retrieve the UID once I run the select function. Where exactly is the response stored?

Thanks in advance!

0 Replies 0