locked
How do you break out of a sequence activity and cause the workflow to end? RRS feed

  • Question

  • I have the following psuedocode logic that I would like to implement:

    1. Get the configuration
    2. Validate the configuration
    3. If the validation is bad
          - Set a workflow variable with the errors
          - Set a workflow variable with the enum value error
          - End the workflow <- This is the problem
    4. Do the rest of the workflow

    My problem is what activity do I use to "End the workflow"?

    If there is no activity to do this, what activity sequence would I use to accomplish the same logic?

    I considered using a Cancellation scope, but I cannot figure out how to invoke the CancelHandler from within the workflow itself?

    Any ideas?

    Thank you in advance.

    Thursday, October 1, 2009 4:53 AM

All replies

  • Hi,

    You can use Flowchart activity inside the sequence for this purpose. Add the FlowChart activity.Then add activities to do validations.Then Declare a variable Isvalid and set its value to True or False based on the validations succeeded or failed.Then  add FlowDecison activity. Set its Condtion property to IsValid and change the execution path of your workflow accordingly. If its false set the workflow variables with errors and if it is true continue with the rest of the workflow.

    suchi
    • Proposed as answer by Sneha Gupta Thursday, October 1, 2009 6:26 AM
    Thursday, October 1, 2009 6:25 AM
  • You might consider using the TryCatch and Throw activities.  Wrap the Validation and the "rest of the workflow" in the try catch, and if the validation is bad, throw an exception.  You could even use a custom exception which includes your specific error detail, and then handle it in the Catch block of the TryCatch.
    Thursday, October 1, 2009 7:32 PM
  • Based on your description, it sounds like step 3 of your sequence can be an If activity.  One branch is taken if the validation is bad, the other branch (Do the rest of the workflow) is taken otherwise.

    Bob
    Wednesday, October 14, 2009 6:14 PM
  • Hello,

    Considering that many developers in this forum ask how to sequence activity in WorkFlow4, my team has created a code sample for this frequently asked programming task in Microsoft All-In-One Code Framework. You can download the code samples at:

     

    CSWF4SequenceWF

    http://bit.ly/CSWF4SequenceWF

    With these code samples, we hope to reduce developers’ efforts in solving the frequently asked

    programming tasks. If you have any feedback or suggestions for the code samples, please email us: onecode@microsoft.com.

    ------------

    The Microsoft All-In-One Code Framework (http://1code.codeplex.com) is a free, centralized code sample library driven by developers' needs. Our goal is to provide typical code samples for all Microsoft development technologies, and reduce developers' efforts in solving typical programming tasks.

    Our team listens to developers’ pains in MSDN forums, social media and various developer communities. We write code samples based on developers’ frequently asked programming tasks, and allow developers to download them with a short code sample publishing cycle. Additionally, our team offers a free code sample request service. This service is a proactive way for our developer community to obtain code samples for certain programming tasks directly from Microsoft.

    Thanks

    Microsoft All-In-One Code Framework

    Wednesday, March 23, 2011 9:45 AM