I’m pretty new to n8n and have a simple question regarding filtering inside the expression editor and was not sure if it’s possible or not. I would like to add a value from a previous node to a filtering process of the current node. Here is a short example:
Ideally, I would like to replace the value inside the second Set node with the variable from node 1. So something like: {{$jmespath($json.data, “[?email==‘Variable from Set1’].link | [0]”)}}.
Is this possible or do I have to build a different workflow? I would appreciate any kind of help.
Hi @Batijko, welcome to the community! This is possible, you can reference any previous node in your workflow using an expression such as {{ $node["Node name"].json["field"] }}.
You can write these expressions manually (which is especially useful when using them in a more complex context like in your JMESPath example) or simply click your way through the expression editor like so (after running your previous node):
Thanks @MutedJam for your quick answer but maybe you didn’t get my question or I asked a little bit imprecise. I would like to refer the first node variable inside the filtering operation of JMESPath. So something like this:
Obviously, is the expression inside the second quotation marks wrong but is there a possiblity to do this somehow or do I have to use the Function node?
Got it @Batijko, sorry for the misunderstanding. I couldn’t get this to work in the Set node/using the expression editor, presumably as the underlying library is somewhat limited.
Yes, that’s exactly what I wanted. Solved it already with a simple JS forEach function but your solution looks pretty easy as well. Thanks a lot for the help @MutedJam
Hey @MutedJam I would have a small follow up question, if you could be so kind and help me out once again. I was playing around with JMESpath a little bit more and in the following workflow I have a small issue:
In the result node apart from item.result_dynamic_id I’m getting all the correctly filtered results. My guess would be that I have to set the right quotation marks because changing the ones inside item.result_hardcoded gives me an empty result as well. I tried all possible combinations without a success. Any idea how the correct expression has to be here to get a result?