If Switch not working

Hi,

I followed the video tutorial and still for some reason the if switch is not working. I don’t see what I am doing wrong. If the column is missing I would like to use the bottom branch of the if statement.

Any ideas?

With thanks,
Venkat

If_switch.knwf (12.3 KB)

Hi @anban , you need to use the correct flow variable in your IF Switch node, which in your case is “Port Choice”:
image

Once you use the correct variable, it’s all good:
image

1 Like

thanks for the reply. But both ports (top and bottom) should be active. Below is the data. I would like to split the data based on col2. If col2 is missing I want to it be in the bottom port and available ones in the top port.

|A|1|
|B|2|
|C||
|D||
|E|3|
|F|4|

Then the Row Splitter or similar nodes should be more useful to you. Switch evaluate to one port (for each iteration in case you build a loop)
br

2 Likes

Thanks, I didn’t know about the row splitter. It works.

The IF Switch will go to top or bottom depending on what’s evaluated in your Rule Engine.

With each row of your table, the Rule Engine will be applied, and will go top or bottom. So, for one line, it will go top, and for another line it will go bottom.

In the end, it all depends on what you are trying to achieve. Based on what you are describing, you probably do not need an IF Switch, but rather splitting the data

Hi @bruno29a, that’s what I also expect to happen but it is not doing that for some reason. Rule Engine is computing true or false for the missing value of the column. Rule Engine Variable creates a flow variable for true or false to top and bottom. For some reason it is not working.

@anban
(The row splitter is, as mentioned, possibly better for your use case but I was determined to see how to make this work! lol)

I played with this one quite a bit and did some searching, and finally reworked your original workflow as this:

So I have two rule engines on different paths. The top one appends a “route_taken” column with the text “through the top”, and the lower appends “route_taken” with the text “through the bottom”.

The results at the final output are:
image

IfSwitchChoosePath.knwf (44.9 KB)

For correctness, it would be wrong of me to suggest that this from my own work. After much trialling and searching, the basis for the above reworking came from here:

3 Likes

(I think that your problem was that without using a loop, the value of the flow variable that governs the switch is derived only on the first iteration, and so you need to use a loop if it is to be determined for each row.)

This is because the workflow is using Table ROW to variable, which would read off only one row

4 Likes

@takbb Thanks for your time and effort. This is very clear! :clap: :clap: :clap:

I followed this tutorial from the office youtube channel KNIMETV https://www.youtube.com/watch?v=E0-zPQsQhIE&t=222s . Are they wrong then ?

@anban , difficult to say without seeing their exact input data, but I’d say the video is misleading.

My take on it is that what they say is right, provided that in Table Reader “Read Transaction” on bottom left contains only the single transaction, and during the video they do say something along the lines of when the workflow processes “the new transaction” (singular). The flow works perfectly for a single row.

So, (assuming I’m right, and I’ve been known to be wrong :wink: ), I’d say they aren’t wrong in the very specific case being demonstrated, but it is misleading in that you’d assume from this that it would work for each individual row in “Read Transaction” … which it does provided there is only one row!!

Without a loop, the flow variable gets set according to the first row in the data set, and then the entire set is processed via that chosen switch.

2 Likes

Thanks @takbb, now it makes sense why it is working for them and not for me!

1 Like

Hello @anban,

@takbb is right. Table Reader “Read Transaction” only reads one transaction. Here is modified workflow from linked video:

Br,
Ivan

2 Likes

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