none
Very basic Switch question (default always seems to execute IN ADDITION TO the correct switch branch) RRS feed

  • Question

  • I have a maddening problem, easy to duplicate in new test projects created just for this purpose, which makes me think I misunderstood workflow switch statements: the default case always seems to execute IN ADDITION TO the correct branch of the switch.

    I have three possible choices for a variable, TargetSystem: "DISK", "INFOIMAGE", or "KNOWLEDGELAKE". 

    I'll eventually be doing some custom routing of a document based on the value of TargetSystem.  Right now, I'm just calling a custom SendMail activity I wrote (as another service) to verify things are working correctly.

    What's happening though is I see the switch (apparently) execute twice.  If I select "DISK", I get an email "routing to DISK", then I get an email "invalid destination: DISK".  "KNOWLEDGELAKE" gives me two emails, "routing to KNOWLEGELAKE" and "invalid destination: KNOWLEDGELAKE".  If I pick an invalid destination, "ETHER", I just get "invalid destination: ETHER".

    I've surrounded every possible route into the switch with additional SendMail calls to ensure I'm not accidentally in a loop and/or calling the workflow twice.  I'm only hitting the switch one time.  A screen snapshot of the section of code is below.  What am I missing?


    • Edited by MarcAaron Wednesday, January 13, 2016 10:14 PM
    Wednesday, January 13, 2016 10:13 PM

Answers

  • OK, maybe I have an answer to this one too.  Apologies to the forum...

    It looks like the designer is inconsistent, in that for switch statements, you can't surround text with strings when you set up your branches.  Note in the above screen snapshot, I am branching on "DISK", "INFOMAGE", AND "KNOWLEDGELAKE".

    Take the quotes around the strings away, and branch on DISK, INFOMAGE, and KNOWLEDGELAKE, and the strange behavior goes away, as below.  I highlighted the only thing I changed to make it work.  The quotes are gone.

    • Proposed as answer by Pengzhen Song Tuesday, January 26, 2016 7:11 AM
    • Marked as answer by MarcAaron Tuesday, January 26, 2016 3:26 PM
    Thursday, January 14, 2016 11:18 PM

All replies

  • MarcAaron,

    I am not able to reproduce your problem, yet.

    The screenshot you included indicates there are two ways to get into the "FlowSwitch" activity. One does a "SendMail", but I can't tell what the other does.

    Plus, it is not clear what the FlowSwitch is using as its "Expression" property.

    Without a bit more information on the previous activities in the flowchart and what variables are being used in the SendMail and FlowSwitch activities, I don't think we can diagnose the problem.

    Jim

    Thursday, January 14, 2016 10:18 PM
    Moderator
  • Thank you for the reply Jim.  Apologies for not being clear.  Here is the ENTIRE workflow, which should answer the question about two ways to get into the workflow. 

    I've highlighted the only two possible paths into the switch in yellow.  Note that each is prefaced by a SendMail(), marked in blue.  This is a safety check to cover each path into the switch, ensure I'm not looping (hitting the switch more than one time).  In every test case, 100% of the time, one and only one SendMail() fires going into the switch.

    The expression for the switch is a variable named gblTargetSystem.  It is a string.  I expect one of three values: "DISK", "INFOIMAGE", "KNOWLEDGELAKE". 

    The switch routes me to one of 3 methods depending on the value of gblTargetSystem and I get an email.  as I'd hope... "Target system is  DISK", etc.  But immediately after that, I get an email from the default path, "Invalid target system "DISK".  Same thing for the other two possible values, INFOIMAGE AND KNOWLEDGELAKE. 

    Hope this makes the problem more clear.  Apologies for such bunny questions.

    Thursday, January 14, 2016 10:55 PM
  • OK, maybe I have an answer to this one too.  Apologies to the forum...

    It looks like the designer is inconsistent, in that for switch statements, you can't surround text with strings when you set up your branches.  Note in the above screen snapshot, I am branching on "DISK", "INFOMAGE", AND "KNOWLEDGELAKE".

    Take the quotes around the strings away, and branch on DISK, INFOMAGE, and KNOWLEDGELAKE, and the strange behavior goes away, as below.  I highlighted the only thing I changed to make it work.  The quotes are gone.

    • Proposed as answer by Pengzhen Song Tuesday, January 26, 2016 7:11 AM
    • Marked as answer by MarcAaron Tuesday, January 26, 2016 3:26 PM
    Thursday, January 14, 2016 11:18 PM
  • MarcAaron,

    Thanks for pointing this out. As you say, this "unquoted string" behavior for the different cases under a FlowSwitch<string> is inconsistent with other designers. Unfortunately, changing this would be a breaking change that would potentially cause problems with existing workflows.

    Jim

    Tuesday, January 26, 2016 4:55 PM
    Moderator
  • Thanks for the confirmation Jim.  I completely understand about it being a breaking change.  As long as the behavior is understood it's not a problem!
    Tuesday, January 26, 2016 4:58 PM