locked
Send arguments when a workflow instance is started RRS feed

  • Question

  • Hi.

     

    Here's my problem...

    My initial state has a state initialization activity which needs some arguments to realize certain steps and proceed to the next state. Problem is that I can only send these arguments through an event...

     

    My question is: Is there a way to send arguments to the workflow, when its instance is started?

     

    Thanks

     

    Monday, June 11, 2007 10:23 AM

Answers

  •  

    You can set the wrokflow properties when you create a workflow instance by using the overload of CreateWorkflow method of WorkflowRuntime object

     

    "public WorkflowInstance CreateWorkflow(Type workflowType, Dictionary<string, object> namedArgumentValues);"

     

    The Dictionary<string,object> holds the parameters that are to be passed to instance. The string should be equal to workflow
    property name , and the object is the value that you want to assign to that property when you create the instance as :

     

     Dictionary<string, object> parameters = new Dictionary<string, object>();
       parameters.Add("Person", new Person(108));
       parameters.Add("TaskTimeOut", new TimeSpan(0,10,0));
       ...
       runtime.CreateWorkflow(typeof(Workflow1), parameters);
       ...
     
    This is going to set the workflow properties for that instance.

     

    For your  state initialization to receive these parameters, you can use Property Binding to bind the workflow properties to your activity properties. (Or promoting your activity properties will yield the same effect, but you will need to watch out for names since it will prepend the activity name to the workflow properties created.)

     

    Thus on createworkflow your workflow properties are going to be set for that instance with parameters passed, then because of property binding the properties on your activity inside the state initialization are going to be set and ready for use.

     

    At least that's how I see things to be.

     

    Hope it helps.

    Monday, June 11, 2007 10:53 AM

All replies

  •  

    You can set the wrokflow properties when you create a workflow instance by using the overload of CreateWorkflow method of WorkflowRuntime object

     

    "public WorkflowInstance CreateWorkflow(Type workflowType, Dictionary<string, object> namedArgumentValues);"

     

    The Dictionary<string,object> holds the parameters that are to be passed to instance. The string should be equal to workflow
    property name , and the object is the value that you want to assign to that property when you create the instance as :

     

     Dictionary<string, object> parameters = new Dictionary<string, object>();
       parameters.Add("Person", new Person(108));
       parameters.Add("TaskTimeOut", new TimeSpan(0,10,0));
       ...
       runtime.CreateWorkflow(typeof(Workflow1), parameters);
       ...
     
    This is going to set the workflow properties for that instance.

     

    For your  state initialization to receive these parameters, you can use Property Binding to bind the workflow properties to your activity properties. (Or promoting your activity properties will yield the same effect, but you will need to watch out for names since it will prepend the activity name to the workflow properties created.)

     

    Thus on createworkflow your workflow properties are going to be set for that instance with parameters passed, then because of property binding the properties on your activity inside the state initialization are going to be set and ready for use.

     

    At least that's how I see things to be.

     

    Hope it helps.

    Monday, June 11, 2007 10:53 AM
  • That's exactly what I needed.

     

    Thanks

    Monday, June 11, 2007 11:40 AM