Skip to content
Airtable list with ...
 
Notifications
Clear all

Airtable list with a filter using an expression

7 Posts
2 Users
0 Reactions
4 Views
mattesilver
(@mattesilver)
Posts: 5
Active Member
Topic starter
 

I'm attempting to implement an upsert operation for Airtable.

I have an Airtable List node that utilizes an expression in its filter field. Previously, I've only used expressions for reading configuration like baseId and tableId. This time, my node is intended to take the primary field's value and return any matching records from the table.

My current setup looks something like this:

"filterByFormula": "={Name} = ‘{{$json["Name"]}}’”

I have several data items as input. After the initial run, all items are inserted into the table. However, when I run the workflow a second time, all names should be found in the table, but only one item is actually returned.

It appears the expression in the filter formula is only being evaluated once.

What am I doing wrong?

Please share the workflow

‘search by external_id’ is causing the issues.

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 0.149.0
  • Database you’re using (default: SQLite): mariadb
  • Running n8n with the execution process [own(default), main]: own
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: docker

Cheers

 
Posted : 05/12/2021 2:22 pm
jan
 jan
(@jan)
Posts: 39
Eminent Member
 

Welcome to the community! Yes, that is currently an inconsistency in callin.io where many of those read operations execute just once instead of once per item. We are currently considering ways to address this in the future. In the meantime, you would need to use a Split In Batches node with a batch size of 1 and iterate over them to achieve the desired outcome.

 
Posted : 05/12/2021 3:13 pm
mattesilver
(@mattesilver)
Posts: 5
Active Member
Topic starter
 

Thanks for your answer.

Is there a way to retrieve the items so I can use them in the merge node with the ‘removeKeyMatches’ mode?

 
Posted : 05/12/2021 4:12 pm
jan
 jan
(@jan)
Posts: 39
Eminent Member
 

Yes, it's possible, though not immediately obvious if you're unaware of the method.

Here's an illustration:

 
Posted : 05/12/2021 4:17 pm
mattesilver
(@mattesilver)
Posts: 5
Active Member
Topic starter
 

:thinking:

I've placed my Airtable call between a Split and an IF node. I modified the function to cache the output of the Airtable node, but it's behaving unexpectedly. It's throwing an error stating that all items must be wrapped in {json:{}}. However, when I do wrap them, the JSON objects appear within the items in the preview.

 
Posted : 05/12/2021 5:07 pm
mattesilver
(@mattesilver)
Posts: 5
Active Member
Topic starter
 

It was generating a list of lists, so I included the following in the collector function:

return newItems.flat(1).map(i=>({json:i}));

Full code:

const newItems = [];

let runIndex = 0;
do {
  try {
    newItems.push($items("Search by external_id", 0, runIndex++));
  } catch (e) {
    break;  
  }
} while(true);

return newItems.flat(1).map(i=>({json:i}));

Now, the 'merge1' node is not invoked when the table is empty (when inserting into a fresh table).
gaaa

 
Posted : 05/12/2021 5:21 pm
mattesilver
(@mattesilver)
Posts: 5
Active Member
Topic starter
 

I managed to create a single formula for all my items using a simple function node.

json
{
"formula": "OR(" + values.map(v => formula).join(', ') + ")"
}

 
Posted : 15/12/2021 8:19 pm
Share: