locked
Help! How do I correlate multiple workflows within a ParallelForEach loop? RRS feed

  • Question

  • I'll admit I'm new at this, but after spending a crazy amount of time looking at samples, documentation, etc. I'm stumped!

    The business scenario is pretty simple. I need to send out an N number of surveys to be completed. I started by creating a sequence workflow, and then sticking in the subsequent ParallelForEach with a sequence of Receive and Sends. My thinking was, the main workflow would receive the criteria and spawn off N number of workflows. These subsequent workflows would send out an email, recieve that the survey had been started, and then recieve that it was completed. When all of the survey workflows were completed, the overall workflow would do some work and be completed. I can't seem to get the correlation to work. BTW, this is a WCF Workflow Service Application and I'm trying to do as much as I can in the designer so the Biz can see it.

    I really think this is a common business problem, yet I can't find any help anywhere.

    THANKS!

    • Edited by Speedr Monday, May 17, 2010 2:01 AM Added more information
    Monday, May 17, 2010 1:53 AM

Answers

  • When you said you can't seem to get hte correlation to work, what errors have you hit? I suspect you haven't initialized the correlation. If I'm understanding your scenario correctly, here's what you can do:

    In your main workflow after "receiving criteria" as you described, you can add a ParallelForEach. This ParallelForEach will iterate through the N email addresses that you will send surveys to.

    In the Body of the ParallelForEach, you will first need an InitializeCorrelation activity (http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.initializecorrelation.aspx) to define a CorrelationHandle (e.g. a variable called myHandle) and to initialize the correlation data using the email addresses that ParallelForEach iterates through. 

    After that, you can have a Receive activity which correlates with the handle and correlates on the key you defined in InitializeCorrelation above.

    For example:

       ParallelForEach activity
          InitializeCorrelation activity
           - Correlation = define a CorrelationHandle variable, e.g. called it myHandle, and set the Correlation field to this handle
           - CorrelationData = initialize on the ParallelForEach [item] and give its key a name, e.g. emailAddress
          Receive activity
           - Correlates with myHandle
           - Correlates on the key you defined in the InitializeCorrelation (e.g. emailAddress)
          SendReplyToReceive activity

    Doing it this way, there will only be one workflow instance. You don't need N instances.

    Let me know if this is not clear. :)

     

    • Proposed as answer by Jeff Cao Monday, May 17, 2010 10:15 PM
    • Marked as answer by Kenny Tian - MSFT Wednesday, May 19, 2010 1:35 AM
    Monday, May 17, 2010 9:02 AM

All replies

  • When you said you can't seem to get hte correlation to work, what errors have you hit? I suspect you haven't initialized the correlation. If I'm understanding your scenario correctly, here's what you can do:

    In your main workflow after "receiving criteria" as you described, you can add a ParallelForEach. This ParallelForEach will iterate through the N email addresses that you will send surveys to.

    In the Body of the ParallelForEach, you will first need an InitializeCorrelation activity (http://msdn.microsoft.com/en-us/library/system.servicemodel.activities.initializecorrelation.aspx) to define a CorrelationHandle (e.g. a variable called myHandle) and to initialize the correlation data using the email addresses that ParallelForEach iterates through. 

    After that, you can have a Receive activity which correlates with the handle and correlates on the key you defined in InitializeCorrelation above.

    For example:

       ParallelForEach activity
          InitializeCorrelation activity
           - Correlation = define a CorrelationHandle variable, e.g. called it myHandle, and set the Correlation field to this handle
           - CorrelationData = initialize on the ParallelForEach [item] and give its key a name, e.g. emailAddress
          Receive activity
           - Correlates with myHandle
           - Correlates on the key you defined in the InitializeCorrelation (e.g. emailAddress)
          SendReplyToReceive activity

    Doing it this way, there will only be one workflow instance. You don't need N instances.

    Let me know if this is not clear. :)

     

    • Proposed as answer by Jeff Cao Monday, May 17, 2010 10:15 PM
    • Marked as answer by Kenny Tian - MSFT Wednesday, May 19, 2010 1:35 AM
    Monday, May 17, 2010 9:02 AM
  • Thank you SOOOO much!!! This worked great. I had gone down this path before, but apparently wasn't doing something right. I persisted this time (no pun intended) since I knew it had to work. I found this link: http://social.msdn.microsoft.com/Forums/en/wfprerelease/thread/1a520c2a-d14b-4785-86cf-94e2f476b4db

    It explained that the name of the key WAS important, which is probably what threw me last time.

    Thank you again!!!

    Monday, May 17, 2010 2:23 PM