Conditional Execution of Nodes based on Table Value to Variable value on a port

I have a workflow that analyzes exported timesheet data and sends team members email reminders if they reported less than 100% time in a given week. I have a branch that loads the timesheet data into a Postgres database. I only want to run the database load after running the validation process a few times until I am satisfied the timesheet data submission are complete. My thought was to manually update a value in a Table Creator Node (On / Off or 1/0) and convert that to a variable, then somehow only execute the DB Loader branch of the process if the Variable = ON or 1 and note execute it if it is OFF or ). I tried the IF SWITCH but couldn’t get that to work. Any ideas how I might do this? A completely different approach to manually turning on /off a branch of Knime logic is fine too.

Hi @mschutterop , there is not much info that you are providing to really answer what kind of approach to take.

I can give you a working demo of using IF Switch, but this would work only depending on what you intend to do.

You should also take the time to read about the IF Switch to understand how it works.

Explaining in details:
The IF Switch is basically a router that will route the workflow either to the top route (officially called “The first choice”), or the bottom route (officially called “The second choice”).

The routing is controlled by a flow variable passed as the PortChoice, and literally takes values “top” for routing to the top, or “bottom” for routing to the bottom.

So, basically prepare a variable with value either “top” or “bottom”. There are a few ways to come up with this variable. You can use a Variable Expression for that, or a String Configuration, or converting from table to variable as you tried to do. In your case, you want to set this manually, so a Variable Expression would make sense, since we won’t have to convert from table to variable. Also, we can set the variable to “top” or “bottom” as opposed to ON/OFF or 1/0. However, if that’s too confusing, you can still use ON/OFF or 1/0. You’ll just need to convert these to “top” and “bottom” eventually - you an use a Rule Engine for that.

Here’s a simple example I put together for you:

In my Variable Expressions, I define a variable “if_route” with value “top”:

And I have some input data:

The IF Switch is configured as follows:

I basically select the variable I created for that purpose in the Variable Expressions (if_route)

The String Manipulation is just appending " processed" to my column1:

This node will run only if the IF Switch gets routed to the top.

Running the workflow up to the IF Switch:

You can see that the bottom route is “closed” - you can see it marked with a red x, since the “if_route” variable is set to “top”.

And continuing running the workflow up to the end:

We can see that the String Manipulation node ran, and the final result is:

Now, let’s switch the routing to “bottom” - we change this in the Variable Expressions:

And let’s run it up to the IF Switch:

Now that the value of the routing has been changed to “bottom”, you can see that the top route of the IF Switch is “closed”, and similarly, anything in that route is also closed (notice the red x at the String Manipulation output). That means that the String Manipulation will not execute, meaning that my result should be the same as what my input.

Running everything:

As you can see, the End IF node ran (it’s green), but the String Manipulation never ran (it has no state).

And the result is as expected - the input data remained untouched:

Here’s the workflow:
Using IF Switch.knwf (12.2 KB)

This is essentially a very basic and GENERIC use of IF Switch. I am pretty sure that it will NOT work for your workflow. It’s more about helping with “I tried the IF SWITCH but couldn’t get that to work” :slight_smile:

It will give you the opportunity to come back with further information, such as what is supposed to happen during (between IF Switch and the End IF) and also after the IF Switch is processed (what happens after the End IF).

There are certain rules with IF Switch (such as table structures should be the same coming out of top or bottom routes), but I don’t want to start talking about all the rules. If you provide the above information, then I can elaborate on what would work based on your needs, or it could even be a whole different approach.


Hi @mschutterop

I think I can satisfy the “completely different approach” idea… :wink:


The component utilises another special node called “Fail in Execution” which is part of the “KNIME Testing Framework UI”. If you get errors in the component, you can manually install the Fail in Execution node from here:


@takbb This was exactly what I needed. Perfect for testing my workflows and making sure certain things don’t fire. Thanks so much. You rock!


@bruno29a This is exactly what I was trying to do your detailed explanation on how the IF works is very helpful. I was able to learn from it. What I was really trying to achieve with the IF was accomplished in a much simpler way by the solution @takbb shared. So I am grateful for both of your responses.


Hi @mschutterop , as I said, this was more about helping with how to use IF Switch, and that it would probably not work as is for your needs.

The “Fail in Execution” is a good approach too, I’ve used it in a few projects where I needed to stop the workflow if some pre-requisites did not meet, and probably @takbb 's component is an excellent wrapper.

I’m glad you resolved your issue :slight_smile:

1 Like

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