How to pass parameters to Work Flow

You can create arguments to workflow and can pass the values from outside. For creating arguments, you can use the Arguments Tab in the WorkFlow designer.

WF Arguments Tab

In the last post I mentioned about loading and invoking a WorkFlow, the WorkFlowInvoker class’s Invoke method has an overload, which accepts inputs parameter, which is type of IDictionary<string, object>. You can create an Dictionary<string, object> and pass it as the parameter to the Invoke method.

You can get the results from the WorkFlow in similar fashion, it is also returning IDictionary<string, object>. Here is the code snippet, which provides one input parameter and accepts the results.

var inputParameters = new Dictionary<string, object>();
inputParameters.Add("CurrentDate", DateTime.Now.AddDays(-20));
var result = WorkflowInvoker.Invoke(activity, inputParameters);
object timeAgo = string.Empty;
if (result.TryGetValue("Result", out timeAgo))
{
    Console.WriteLine(timeAgo);
}

You can use any type as the argument type.

Happy Coding :)