none
How to modify Variables in a WorkflowAplication programatically? RRS feed

  • Question

  • A WorkflowApplication runs an Activity, and an Activity can have Variables inside it. How do I modify or access these variables?
    Wednesday, January 19, 2011 7:50 AM

Answers

  • Louis,

    You can use In/OutArgument in a custom activity. E.g. build a custom activity that has an InArg and OutArg defined, and add an instance of this custom activity in your root sequence. You can pass the variable defined in your sequence to the custom activity's InArg, and return value to the sequence using the OutArg.

    Is this the way you want your data flow?

     


    Cecilia Leung This posting is provided "AS IS" and confers no rights or warranties.
    Friday, January 21, 2011 5:22 AM
    Moderator

All replies

  • Hi,

    The veriables are internal to the workflow instance. If you want to have access to internal data in the workflow you should add arguments to the workflows and activities and access the arguments.

    Regards,

    Alan

     


    http://www.CloudCasts.net - Community Webcasts Powered by Azure
    Wednesday, January 19, 2011 8:15 AM
  • As far as I know a WF4 workflow doesn't have Arguments, they have Variables. How to access those?
    Wednesday, January 19, 2011 9:37 AM
  • I found this link. http://msdn.microsoft.com/en-us/library/dd560894.aspx

     

    There is an explanation about how to set InArgument and retrieve OutArgument of the root activity in the WorkflowApplication. However, in my case the root activity is a Sequence, which doesn't have InArgument and OutArgument, but it has Variables. Is there any way I can access/modify these variables?

    Thursday, January 20, 2011 7:57 AM
  • Louis,

    You can use In/OutArgument in a custom activity. E.g. build a custom activity that has an InArg and OutArg defined, and add an instance of this custom activity in your root sequence. You can pass the variable defined in your sequence to the custom activity's InArg, and return value to the sequence using the OutArg.

    Is this the way you want your data flow?

     


    Cecilia Leung This posting is provided "AS IS" and confers no rights or warranties.
    Friday, January 21, 2011 5:22 AM
    Moderator
  • Hi Cecila,

    Thanks for your reply. It sounds like a good idea. However I have some problem, when I created my custom activity and make this the root activity, I can't seem to make this custom activity the scope of a Variable. I created another thread here , can you give some suggestion?

    Friday, January 21, 2011 7:02 AM
  • Louis,

    I saw that your other post has been answered already. :) Yuanji's answer seems to match what you want. You may also take a look at this sample, downloadable from here, which implements a simple-concept custom activity with Collection<Variable>. You can see how it's used in the Program.cs or you can build the project and drag the custom activity to a designer, just like what Yuanji suggested.


    Cecilia Leung This posting is provided "AS IS" and confers no rights or warranties.
    Friday, January 21, 2011 3:54 PM
    Moderator
  • Hi, Louis

    Are you trying to create your own workflow in pure c# code? if yes, the following blog entry I wrote some time ago could be helpful to you:
    http://xhinker.com/post/WF4Authoring-WF4-using-imperative-code%28II%29.aspx

    Regards
    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    Monday, January 24, 2011 6:20 AM
    Moderator