locked
Get Iteration variable from ForEach Workflow Activity RRS feed

  • Question

  • Can any one assit me in ascertaining if the following functionality is available?

    Within a hosted workflow designer, i have a ForEach activity that contains a sequence and subsequently a custom activity lets say a get data table activity.

    When i launch a custom activity editor for the get data activity i would like to be able to determine what variables are available to this activity. Now i am happy that i can easily navigate through the ModelItem tree and check for variables at certain points of the type i am interested in. However I am not sure i am able to use the implicit iteration variable used within the ForEach activity.

    I am not sure if this is possible because the iteration variable is not exactly a hard and fast variable that would be available in our designer. However obviously it is certainly in scope of my activity because i can bind it manually.

    Any help on this question would be greatly appreciated.

    Thanks,

    Ol

     


    OB
    Thursday, March 24, 2011 11:18 AM

Answers

  • Hi Olly,
    The tricky aspect of ForEach which is giving problems is that the iteration variable is not a Variable at all, it is actually a DelegateInArgument.

    You can see this more clearly if you look at the serialized XAML than if you are looking in designer:

    <ForEach x:TypeArguments="x:Int32" Values="[{1, 2, 3, 4}]">

       <ActivityAction x:TypeArguments="x:Int32">

         <ActivityAction.Argument>

           <DelegateInArgument x:TypeArguments="x:Int32" Name="item" />

         </ActivityAction.Argument>

         <WriteLine Text="Can I have a little more" />

       </ActivityAction>

    </ForEach>

     
    You can solve the issue by writing code to iterate through the parent chain of the model item and checking if there are DelegateInArguments. But even that may not be a fully accurate implementation of which variables are visible to the activity at runtime, it's a somewhat complex topic and I could need further research myself to find out if there's a canonical way of finding the exact set of variables/arguments in scope.

    I hope this at least helps solve your immediate problem,
    Tim

    • Marked as answer by Andrew_Zhu Thursday, March 31, 2011 3:26 AM
    Monday, March 28, 2011 10:46 PM