[Solved] How to Filter data from Airtable

I was able to get the search functionality to work in my home screen to search on specific titles. I am now trying to do similar functionality on a profile screen that would display only the current user’s posts (so the ones with the user’s email in the email field). I’m using the same idea of generating lists for the Key, email and title column. And then filtering through the email list to only use the ones that have the user’s email. I don’t have error handling to it freezes. I know it’s retrieving the lists correctly cause I used debugging to see that. It’s failing in the filter list code.
Here is the code for my home screen with the search, and then the code for my profile screen that should filter records with user’s email. Any ideas why the latter is not working?


Hi, @qaburns014w! :wave:

These steps might help you -

  • image
    Here, try to replace the contains block with = block.

  • Also, replace this direct block image with an updateList function, which should have this block inside it.

  • So it would look like -

    image

  • And call the updateList function here (at the last) -

    image


Hope this resolves your problem.
Thanks! :blush:

2 Likes

No that does not work. I know that getList works and builds the lists correctly for all 3 (Title, Key and Email). I played around and set the list viewer to those to make sure. And I know it goes into FilterList but it fails somewhere in the count functionality. This I the exact same code I used in the home screen. Why would it not work the same?

Probably has to do with the information source. Are the variables your using initialized by the time you are trying to call them?

Yes they are all initialized like they were in the home screen.

Can you debug step by step. As you pass info from one set of instructions to the next, display it on a label. See where the breakdown takes place in the flow of info

Yes, I’ve done that. I know it’s failing when setting the temp objects.

I tried this and it says undefined. But I know the list is there because I set the ListViewer to display each list and it worked.
Screen Shot 2020-03-26 at 10.46.45 AM

So, check what you are setting them from. Before you set the value as last in list x. Make that value display on the screen to ensure you are setting a value.

Do it without the loop.

Just, in app list get number 1 instead of number i

Do you use any special delimiters or have commas in your title names?

I tried that and that is where the problem is. I set a text label = in list get #1 for each of them. Even though the lists are created since I tested that, it can’t get the value out. And no I don’t have any special delimiters in my titles.

I put the same exact code within one block as you can see in pic and now it works!

THis could be an issue of the code executing prior to the data being save into the variables. It takes time for each airtable call to be sent and received. if you do not put blocks in the ‘then do’ that you want to happen after the data has been received they will execute them as soon as the data has been sent without waiting for the data transmission to be received.

IMPORTANT: when using a block with a ‘then do’ section. this means you may want to wait on the code to complete some action prior to completing the next. these actions are asynchronous meaning they happen when they are able to and not necessarily in order.

its possible that your filter runs before the data has been fully received and therefore will not produce the information you think that it should.

the way you have fixed your code alleviates that issue by making the app wait to execute the blocks until the data has been received.

You should almost always nest blocks if you are reliant on the data from the purple method blocks.

1 Like