Issue with assigning variables (from other Branches)

Hello!

Been trying to find why my workflow is not successfully passing the spreadsheet ID/URL from one branch to another (see below image):

Basically the first branch scrapes data and uses one bundle to create a spreadsheet name with the query search string. The second branch then adds/appends the bundles to the spreadsheet.

When testing the workflow, it seems that the variable is “undefined” even through the input has the data… Ive tried usingt he Google Sheets, Execute Data, Set Nodes, but cant understand why using a variable doesnt work (but without the variable does…)…



Would appreciate the help!

Graham

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Welcome to the community @Graham_Beck !

Tip for sharing information

Pasting your n8n workflow


Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.

```
<your workflow>
```

That implies to any JSON output you would like to share with us.

Make sure that you have removed any sensitive information from your workflow and include dummy or pinned data with it!


Do you have spreadsheetId available in all the outputs of both nodes - “Execution Data” and “Set Bundles To Iterate”?

The error indicates that is is missing somewhere. You showed that is it present in “Execution Data”. I can conclude it is not the case with “Set Bundles To Iterate”.

Yes, its not there as that branch doesnt yet have the SpreadsheetID. I thought the “Execute Variable” allows you to reference the variables across branches? Is there any way to do this? Whats the easiest fix here so I can understand.

Basically, how can I easily pass variables from one branch to another branch (in the same workflow)?

You need to engage Merge node to exchange (combine) the data from both branches.

Ok thanks I added the Merge Node to “append” the Spreadsheet URL/ID to the bundles of business data. My issue now is I need to add a step in-between the Merge and Google Sheet to prevent the Google Sheet URL and ID from being added to the Google Sheet itself.

Updated N8N Workflow:

Merge Node:

Sample Google Sheet Output:

Basically, my ask is how can I pass through the Google Sheet meta data (without actually adding it to the Google Sheet)? I only require the Spreadsheet URL and Sheet Name (for the append/update) of the actual bundles I want added as rows to the sheet.

I tried the Split Function, but it only seems to output the URL and Id only.

Hey @Graham_Beck , I do not think that “Append” is the right operation for Merge in your case.

I would imaging the following to be considered

  1. Merge could be used to pass the data from branch 2 only once input is available on both branches (“Chose branch” mode)
  2. You need to have the headers of the spreadsheet created before hand
  3. Having the headers prepopulated (not including the spreadsheet IDs) will ensure the correct automapping of the data
  4. Having access to the spreadsheet ID that was created in the workflow could be achieved by referencing the node that has that data, for example {{ $(Google Sheets).first().spredsheetID }}, see Output of other nodes | n8n Docs

How to created headers with spreadsheet creation is demoed here, Issue with Google Sheets API OAuth2 Callback While Creating Sheets with Headers in n8n - #4 by ihortom.

Ok, when I reference the Google Sheets node directly for example: {{ $node[“Google Sheets”].json.spreadsheetId }} it seems to work!

This way I can pass input 2 by itself and reference the Ids from the Node.

Last question, I want to add a Google Drive share request (so after the Sheet is complete) I want it to invite the designated user to the GSheet. Whats teh best way to do this?

See image here:

For some reason I am getting an error.

Hey @Graham_Beck , I believe the error comes about because you list more than one email address.

You either need to use a few Google Drive nodes for each user, or the users should be members of the same group.

1 Like

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