Re: Scripting: Filter within a for loop and then have a for loop from the filter

1599 1
Showing results for 
Search instead for 
Did you mean: 
8 - Airtable Astronomer
8 - Airtable Astronomer

Is is possible to do multiple layers of filters within for loops? What is the best way to do this, otherwise?

So for instance, I am taking a survey, finding matches for that survey and then needing to do counting for those matches from a different table.

There are at least three tables I am filtering by along the way.

5 Replies 5


Despite being able to code anything you can imagine for filtering, the best way is to not code at all for filtering. Instead, lean on views to do all the filtering and allow the scripts to read the views, then counting becomes a very simple script.

Hi Bill - We need to do it all in the scripting at the moment. Even if we filter by user and session, it’s too complex to do the calculations without the filtering.

That being said, what’s the best way to do this with filtering?

I am getting an error ‘Block-scooped variable used before declaration’ even though it is below the filter.

I think this is a javascript error - tough to debug without seeing the script.

Have you, perhaps, inadvertently reused a variable name?

I noticed in another post that you had variable names like f_client and result2. I would encourage using much more descriptive names, regardless of their length or tedium of typing them, because 1) it makes your code easier to read and reason about, and 2) makes it less likely you’ll accidentally duplicate a variable across scopes.

Hi Jeremy -

No, the error is coming after. This is the code:


for (i = 0; i < f_thisclient.length; i++) {

let symname = f_thisclient[i].getCellValueAsString("Symptom")

let clemail = f_thisclient[i].getCellValueAsString("Client_Email")

let sesidlinked = f_thisclient[i].getCellValueAsString("Session_ID_linked")

let sesidnl = f_thisclient[i].getCellValueAsString("Session_ID")

let syman = f_thisclient[i].getCellValueAsString("term_id_via_cr_table")






// We want to filter out the relationships table await: result3 for only this symptom

let f_theseR = result3.records.filter(f_record => 

//works f_record.getCellValueAsString("Client_Email") ==v_this_client_string

    f_record.getCellValueAsString("id_L") ==syman 


for (j = 0; j < f_theseR.length; j++) {

    let defstr = f_theseR[j].getCellValueAsString("Deficiency, System Failure, or Irritant")

    let defnum = f_theseR[j].getCellValueAsString("id_R")

    // Need to add 

    let f_theseR = result3.records.filter(f_record => 

        //works f_record.getCellValueAsString("Client_Email") ==v_this_client_string

        f_record.getCellValueAsString("id_R") ==defnum