How to store variables based on dynamic data, for use throughout workflow

Hi,

I am working on a workflow which is used to generate a report based on a set of json data.

I am trying to figure out how to setup some global variables to track specific things throughout the entire workflow.

For example, in the data object I have a key called Type which can have 5 different values. The json data contains many objects (hundreds) each with the Type key but with one of the 5 values:

“Type” can be either "JavaScript, eTag, First Party Cookie, Third Party Cookie or Local Storage.

I need to count how many instances of each type occur in the json data and store them as a variable so when I get to the end of my workflow (which builds the report) I can use the variables in the report.

For example - I might have 547 different objects in the json Data with the following breakdown for the Type key:

JavaScript: 293
eTag: 142
First Party Cookie: 27
Third Party Cookie: 49
Local Storage: 36

I cannot see how to store them and access them globally within the workflow so I can use them to dynamically generate the report at the end. I have no issue counting them, I can do that with a generic code node and for loop but when I iterate and update the counts accordingly, it saves the count at each iteration directly into the main $item.json object as opposed to separate variables outside of the items (I hope that makes sense).

Thanks in advance.

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:

Hi @ThatPrivacyGuy

Not sure if I follow correctly, but if you just need the count all the types at the end of the workflow you can probably achieve that with a Merge and Summarize node or even the Compare Datasets node.

You could also make that a sub-workflow that will “report” the numbers back to the parent workflow where you create your report.

Let me know if that makes sense? You can also share your workflow here for better context.

Tip for sharing your workflow in the forum

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>
```

Make sure that you’ve removed any sensitive information from your workflow and include dummy data or pinned data as much as you can!


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