Help

Filter values based on multiple values

Topic Labels: Scripting extentions
6449 25
cancel
Showing results for 
Search instead for 
Did you mean: 
Rose_Haft1
8 - Airtable Astronomer
8 - Airtable Astronomer

Hi there - We are trying to filter records based on multiple IDs but it is doing so in a loop so we can’t use the || or && as we don’t always know if there are multiple and often times there are 5 or more variables.

We want something like this:

var these= tabale_await.records.filter(f_record => f_record.getCellValueAsString(“Term_at_id”) == [any of these])

Is it possible?

25 Replies 25

Sure, as long as it’s smaller than 100k, you could save and re all it from a long text field. But it would have to be stringified first and parded when reading back into your script. I would focus first on making it dynamic and then if there are reasons to persist the index, work on that part separately.

The format is a JSON object; the structure is whatever you need the index to be. For example, a list of customer name keys might look like this in a variable named oCustomers:

{ "ABC Transportation" : {
   "customer_id" : "1001",
   "customer_contact" : "Jimmy Johns",
   other attributes needed for the index...
   }
}
... objects representing rest of the customers ...

With such a structure, one could instantly know the customer ID with one line of code in about 2 milliseconds (i.e., all without iterating across the data table):

let customerID = oCustomers['ABC Transportation'].customer_id;

Is the o in the variable name an instance of Hungarian Notation?

Um, no - it’s just an indicator (for my team) of a parsed JSON object. sRecords (for example) would be a serialized JSON object. Declaring (in code) the nature of JSON values is helpful where lots of integrations exist.

Isn’t that a variation of Hungarian Notation?

It’s a prefix that states metadata about the variable–in this case the variable’s data type.

Rose_Haft1
8 - Airtable Astronomer
8 - Airtable Astronomer

I am back to this problem again trying to work in automation.

I am wanting to filter multiple records by an array. For instance – I am trying to match recipes that have wheat products in to find the ones with gluten.

Gluten will have multiple different names in the table, and I need to filter by these multiple record IDs. Is it possible to do this without hard coding the &&?

Yes, it is possible.

One way is to use the array function includes() inside a loop on the ingredients.

Another way is to make an array that includes all the ingredients and all the gluten ingredients. Then make a new array that contains only unique ingredients. Assuming that each ingredient is listed only once in a recipe, if the two arrays are the same length, there was no gluten in the original list of ingredients.