How To Reference A Variable Set From Various Places

Hey folks, could anyone help me with what I believe is a very simple issue.

How can I set a variable from various sources in a workflow, then call it later.

For example - say I want to set a field: “Listing_URL” and then send that to a google sheet, but I have 2 paths where that listing url could be coming from; path A and path B. It will only ever come from one path at a time.

For example say:

Path 1 - Perplexity - Set “Listing_URL” -\
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀- Get HTML - Send To Sheet
Path 2 - Lookup Sheet - Set “Listing URL” -/

If the send to sheet node was immediately after the Set Listing I could use the relative reference {{ $json.Listing_URL }}

But it’s not, there are several steps in between and many paths with many different ways the Listing_URL field is being set.

Is there a way to set and call persistent variables? I thought that was what the Set node was for but it seems that to look it up I have to call the node that it came from by name? Am I being stupid?

:slight_smile:

That is a way to access data from a node, as example(assumingyou have a node called TEST):

``{{ $(‘TEST’).item }}``

Yes but if I have the same variable being set in multiple places, I can’t call the node by name - it’s dynamic.

Path 1 - Set1 Email -
Path 2 - Set2 Email -

If I then need to call “Email” somewhere, I can’t. I need to know which node it was set in.

Since you have the same variable for either path, what you want to do is

Path 1 - Perplexity   -\ 
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀          --> Set “Listing_URL” --> Get HTML --> Send To Sheet
Path 2 - Lookup Sheet -/

Then you can ref that Set "Listing_URL" node without any ambiguity.
Moreover you don’t even need that separate Set "Listing_URL" node, you can just ref one of the urls from the corresponding node - Perplexity or Lookup Sheet.

With Set listing url node:

Without setting listing url node:

In this example you can manipulate the path by changing the if statement.

1 Like

Got it, so you are just using an expression to write the Listing URL field as either/or one of the sources, rather than trying to write the same named field from two sources then call it based on its name.

Understood on the logic but, could you think of any more… “point and click” way for me to do that that doesn’t involve me learning to write that expression? I could use ai to do it every time but thats not ideal :slight_smile:

If the nodes are miles apart or there are loads of sources etc it can become very unwieldy trying to write that expression for me :slight_smile:

Hey @JasonBroderick honestly, I would just read on expressions, they are a powerful instrument and can help greatly in referencing information from other nodes. Moreover, the editor usually even helps you with syntax completions there. Generally there are two things you want to do with expressions in context of referencing the output of other nodes - previous node, which you can get from $json, for example, if the previous node outputs a field “url” you could access it with:

{{ $json.url }}

and if the output you are trying to get is of a node, which is not immediately preceding the node where you are writing the expression, you could use the following syntax:

{{ $("Name_of_node").item.json.url }}

You can often use drag and drop when you need an expression. Drag the fields from the input pane to the output pane on the node configuration page and you will get yourself an expression.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.