Query regarding CodeActivity InArgument while working with a Statemachine

Answered Query regarding CodeActivity InArgument while working with a Statemachine

  • Tuesday, May 15, 2012 6:31 PM
     
     

    Hi,

    I have a StateMachine Workflow and under that in the initial state Entry activity I have dragged a CodeActivity which is internal having an InArgument<String> named RequestID.I am using WorkflowInvoker.Invoke to start the workflow.How do I pass the InArgument within the Codeactivity while starting the workflow?

    Regards,

    Sandip

All Replies

  • Wednesday, May 16, 2012 3:51 AM
     
     Answered

    Hi Sandeep,

    You can declare your INArgument at workflow level and pass that workflowInvoker or workflowApplication object.

    Please follow this link

    http://msdn.microsoft.com/en-us/library/dd560894.aspx

    http://blogs.msdn.com/b/rjacobs/archive/2011/05/25/passing-values-between-workflow-activities.aspx

    Activity wf = new WriteLine();

    Dictionary<string, object> inputs = new Dictionary<string, object>();
    inputs.Add("Text", "Hello World.");

    WorkflowInvoker.Invoke(wf, inputs);

    Thanks,

    Madhur


    MB

    • Marked As Answer by sandip_ray63in Wednesday, May 16, 2012 4:03 PM
    •  
  • Wednesday, May 16, 2012 1:48 PM
    Moderator
     
     Answered

    Hi Sandip,

    Madhur is correct. You can declare the InArgument at the workflow root level, and pass in the value when you invoke the workflow. Then in the workflow designer, after you drop your custom code activity into the Entry action for the state, you bind to the workflow level InArgument to the InArgument of the custom code activity. There is an example of doing this in the WF4 Getting Started Tutorial How to create a workflow. There are 3 versions of workflows created (Sequential, Flowchart, and State Machine), I am linking to the State Machine tutorial here since you said you were using state machine:

    http://msdn.microsoft.com/en-us/library/gg983472.aspx

    In "To create the workflow variables and arguments" a MaxNumber InArgument is defined at the workflow level.

    In "To add the workflow activities" in the Entry action of the first state we add an Assign activity, and then bind its Value InArgument to an expression that references that MaxNumber InArgument. You could do the same thing in your state machine, and if you just need the value of the argument (without any other expression evaluation like in my example) you could just put the argument name.

    Thanks,

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm