Exit Table Row to Variable Loop if Table is Empty

Is there an easy way to exit out of a Table Row to Variable Loop if there are no values in my table?

I’ve tried bypassing with a Table Row to Variable > Java Edit Variable > IF Switch, but I can’t seem to get the java to recognize the “missing” variable (I’m new at Java too).

Any help would be appreciated.

Never mind, solved it. I think. I had to update the java script to:

out_port = (v_AcqFieldName.equals(“missing”))?“bottom”:“top”;

And put the IF Switch inside my loop, not outside.

1 Like

Glad you were able to find a way - thanks for posting your solution!

Hi @davidbaker,

it’s funny but when I read your question I didn’t realise that the Table Row to Variable loop would actually perform an iteration with an empty table, but I learn something every day!

Your solution works for you so that’s good. It’s slightly frustrating it cannot differentiate a “missing” string and the actual string value “missing”. Likewise if your data had been numeric, it would have presented you with 0 which would be difficult to distinguish from an actual zero.

A couple of alternatives, depending on your use case could be to get the number of rows as a flow variable prior to entering the loop

image

Then your Java Edit Variable could perform:
out_port = v_NumberRows==0?"bottom":"top";

On further experimentation, you could possibly make use of the empty RowID as follows. I was expecting it to be null but it is actually an empty string when there is no row:

out_port = v_RowID.equals("")?"bottom":"top";

Alternatively if you don’t want to enter the loop at all, then an Empty Table Switch to bypass the loop might be an option, but you’d need to tie up the different possible flows at the End If to make them compatible which may add some complexity depending on what you are doing inside the loop

2 Likes

Thanks @takbb! I really like the row count solution. I think I’ll change mine to that. It seems more elegant, as it doesn’t use column names from my table, so is more generic.

2 Likes

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