How to get Failed Node Name and the exit code of failed node?

Hi Friends

I am trying to create a workflow as shown in the below image. I need help with “Function Node” before the email. To give a brief background, the workflow starts with getting Date and Time and then 3 execute cmd nodes get executed. Each of these executes cmd node run’s a python script then Status Checker checks if the exit code of all 3 parent nodes and if one or more executes cmd node fails then the false part will get kick-off were i am using function node to get the names of the failed nodes set the name as a string. for exam if Run-1 and Run-2 is failed the that function should set a string “Run-1, Run-2” and then this string of failed node name get sent via email.

I am having trouble dynamically getting the name of failed nodes. I want an approach where if I add one more execute cmd nodes in the future then I don’t have to modify this function.

Thanks,
Monil

That should be possible with $items:
https://docs.n8n.io/nodes/expressions.html#method-items-nodename-string-outputindex-number-runindex-number

You can have a loop which with each iteration increments the index. That index you use to build the node name like const nodeName = "Run-" + index; and then use with the $items function to query its data. Around $items you add a try-catch block. As long as it is successful and returns data you keep on iterating. Once it fails and you end up in the catch you know the node does not exist and you can break out of the loop.

Did not test it but should theoretically work.