Empyt Table Switch | 'Active Scope End node in inactive branch not allowed' error'

Hi Friends
What is the best workaround for the ‘Active Scope End node in inactive branch not allowed’ error’

In the image below, I don’t want an Excel file to be created when the result is an empty table. I need to bypass this step.

The issue is that the Excel node doesn’t have a table output, and to close the Empty Table Switch, I have to use an End IF node.

When I use the configuration shown in the photo, I get the following error: ‘Active Scope End node in inactive branch not allowed’

Any ideas to not bypass empty table through excel node?

1 Like

This configuration also not work

Inside Empty Table Switch

The Flow variable from the excel node to the loop end transports the deactivation. You have to wire it in a different way

Hi @Felipereis50 ,

In your first screenshot, place an Add Empty Rows node (in more recent version of KNIME this is now named the Constant Value Row Appender node) between the Empty Table Switch and the End If on the upper branch. Configure this this to add an additional zero rows so it does nothing!

Then attach the output flow of the Excel Writer to the input flow variable port of this new node. Remove the link between the Excel Writer and the Loop End.

The purpose of this additional node here is purely to act as a way of linking the flow variable within the branch, which as you have discovered can be problematic.

If you have the Node Pit Power Nodes installed, you can use one of the No op nodes for this purpose.

2 Likes

@Felipereis50

I happened to have run into the same problem you have in your first screenshot and found a forum topic with a bug reported almost 10 years ago, which included some workaround attempts - see here for details:

What worked for me is to move the logic in-between the loop start and end into a component - i.e. what is in the green box in below screenshot:

The second screenshot you shared I think was commented on enough - having the Empty Table Switch inside of the loop and closing with End If outside of the loop just does not work (end if needs to happen inside of the loop which is what the error you see in the second screenshot pretty much means).

Hi @takbb

Like this? (see screen shot 1)
But, even though I’m lost!! Because I need the loop end node

screen shot 1

A less-than-ideal solution I once implemented:
To work around the issue and avoid keeping empty Excel files, I did the following: whenever an empty file was saved to the “empty excel” folder, the filename would include the word “missing.” I then used the “Transfer Files” node with the “Delete source files” option checked. Essentially, after saving all the files at the end of the loop, I would identify the ones containing the term “missing” and delete them. This made it look like they were never saved in the first place.

However, today I decided to reach out to you for a better way.*

Guys, I took a moment to think it through, and this was my solution:

The table was already coming in empty even before the Metanode. The Group Loop was simply grouping by category for each Excel file I was about to create.

Then it became clear: if the table is already empty, I don’t need to pass it through the Group Loop. I can just handle it within the Empty Table Switch and go straight to the End IF.

Problem solved.

3 Likes

Hi Martin,

I’ve reviewed your suggestion, but there’s a catch: I have no idea how Try-Catch works.** **To be honest, I’ve tried studying it, watching videos, and even downloading example workflows, but believe it or not, I still don’t get it. Whenever I see topics involving those nodes, I honestly get a bit discouraged!

I know Try-Catch is a widely used technique in other programming languages, but I haven’t grasped the logic of what I’m supposed to do once it enters that node. I watched some KNIME explanation videos, but they weren’t very clear to me.

Actually, do you happen to have a video of your own that covers this node?

Off-topic:
Today was the first time I managed to use a “Recursive Loop” and actually understand how it works. It was exactly what I needed—it completely blew my mind! I had a validation rule that needed to be re-evaluated with each iteration until all rules were cleared. Since each rule has a different function, the value fields changed every time, so I had to iterate at least four times. Long story short, the Recursive Loop saved me.

This is why it’s so important to watch videos and try to learn what each node does. Though, with so many new things like statistics and machine learning nodes, it’s impossible to know them all without understanding the underlying concepts. It’s great to have people like you to help out! I also managed to implement “Call Workflow Service” along with “Workflow Input” and “Output.” I found it really interesting to call other workflows without needing to keep them all open.

Hi @Felipereis50 ,

I see you already have come to a solution, but just to clarify what I was suggesting, I’ve edited your screenshot to show what I was trying to suggest

This is a method of how to connect a non-data-port node (eg Excel Writer) to the end of an END IF or other END node that is expecting a data table.

This made assumptions that your workflow required the Empty Table Switch to be within the loop as you had implied, but actually, on thinking this through, within the Group Loop Start-Loop End construct, there can never be an empty result set (since if you are inside the loop, there must always be a group which means you have at least one row!).

So what you came up with was the more correct solution. So if what you have ended up with is now working for you, please mark your own solution as correct. :wink:

1 Like

Hi @takbb

Oww I see. Now I understand what you said.

Great method.
I will definitely consider your tip. I’ll leave it noted for another opportunity. Thanks my friend.

1 Like

This error happens because the End IF node is placed in a branch that is not executed.

Fix it by keeping the IF structure complete and only placing the Excel Writer inside the active branch. Do not try to close the switch inside an inactive path.

Simpler workaround check if the table is empty first using a Row Count or Empty Table Switch, then only route non empty data to the Excel node and skip it entirely otherwise.

1 Like