Else If doesn't work how it should

The logic here is on row 0 I want to run the Business Days activity. And for any subsequent row where the RUN_DATE value is different from the previous row, also run the Business Days activity. When the first condition is met it shouldn’t bother processing the second condition, but it does anyway.


The workaround for this is to change the “Else If - Condition” to: index > 0 AndAlso NOT CurrentRow(“RUN_DATE”).ToString = DT_Main.Rows(index-1)(“RUN_DATE”).ToString

But I shouldn’t have to do that.

Hey Paul, apologies if I’ve misunderstood what you are trying to do but I’ve just tried it and it seems to work on my setup albeit I have much simpler conditions.

Yours works because you aren’t doing what I’m doing. I’m referencing a row index in a datatable, in the second condition. That’s why the error is that row index -1 doesn’t exist. It’s processing the ElseIf even though the first condition is met. Yours is doing the same thing, but your second ElseIf condition can’t error out so you’re not getting an error. Change your second condition to…

dtTest.Rows(intDtIndex -1)(0).ToString = “Something”

Thank you for reporting this one, it indeed looks like it shouldn’t trigger the second condition and it does (I reproduced this quite easily on my end).

1 Like

Small update. Unfortunately, this one won’t be fixed any time soon.

We investigated and it looks like the CoreWF tries to evaluate all conditions first before actually executing the activity, which makes it really tricky to fix for us and we decided to keep the behaviour as it currently is.

We will make sure we document this edge case in the activity documentation.

Got it. Might be worth putting into the documentation that use of AndAlso can solve it. For example, if you’re trying to do something with these Else If conditions…

  • Dictionary Key “test” = “value”
  • Else If Dictionary Key “test” = “value2”
  • Else (do things if the value is something else or doesn’t exist)

Then the way to handle it is…

If yourDict.ContainsKey(“test”) AndAlso yourDict(“test”).ToString = “value”
Else If yourDict.ContainsKey(“test”) AndAlso yourDict(“test”).ToString = “value2”

1 Like