$items().length needs the node name to work correctly in the "Exec once" mode?

Hi. I used to use a Function node to count total number of records with items.length. But recently I was told about the {{$items().length}} expression. However, it works just partially.

  1. I use it in the “Execute Once” mode
  2. I write {{$items().length}}.

It produces correct results as an expression, but wrong output. Please see:

When I put the node name {{$items("Customer Datastore").length}}, everything is OK

Hi @artildo, when using $items() without a node name, it would refer to the current node. When the Execute Once setting is enabled, the node will only take the first item it receives into account and ignore everything else.

So when using Execute Once, you might want to keep referring to the previous node in the $items() method for the time being (as you have already found out), though I understand this might not be super intuitive. I have thus added it to our internal list of possible improvements so we can look at this at a later stage.

@MutedJam , thank you for the answer. I understand that when Execute Once is enebled, the node possibly interacts with the only first incoming item. But then the expression $items() is misleading , giving the total incoming array. Othewise on the first screenshow I would have 1 on both the left and the right.

Maybe a remark in the $items() help section (without the Node name) would help. Something like: “If the “Execute Once” mode is on, then this exression returns only the first item of the incoming data”.

Looks totally correct to me and nothing we want to change as they are two totally different things. One is the incoming data, the other one the number of times the node will be executed.
Just because the node should execute once, does not and should not change what data the node receives and what it should be able to access.
The most simple example would be somebody wanting to send a simple SMS informing about the number of orders that have been received. That person needs then to be able to access all the items and not just the first one. Also quite possible that for another use case somebody wants to access a particular item like number 5 and not 0.

Very sorry, totally ignore my post. I understood it totally wrong. You are 100% right, it currently behaves wrong and it should behave differently.

1 Like