How to use a switch statement in a code node

Describe the problem/error/question

I have a large number of items output from the previous node - each item has a property called Risk which is either Low, Medium, High, or Critical.

I want to count the number of each Risk level and return them (along with input.all()) to the next node. But I can’t seem to get the numbers to increment.

What is the error message (if any)?

No error just the count variables remain as 0.

Please share your workflow

Share the output returned by the last node


{
"output": 
{
"Script Name": 
"https://www.example.com/core/misc/ajax.js?v=10.3.5",
"Issues": 
"Data transmission lacks encryption, third-party asset loading risk, potential for command injection, user interaction data exposure.",
"Category": 
"Security and Privacy",
"Risk": 
"High"
}
},
{
"output": 
{
"Script Name": 
"https://www.example.com/core/modules/views/js/ajax_view.js?v=10.3.5",
"Issues": 
"No relevant issues.",
"Category": 
"Privacy and Security",
"Risk": 
"Low"
}
},

Information on your n8n setup

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

Ok I fixed this, I needed to reference item.json.output.Risk not item.json.Risk

1 Like

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