Passing parameters into the workflow.

Hi,

I'm very new to workflow, and need help... I created a workflow library that has a custom workflow action developed. Then I used a winapp to test the workflow, in preparation to deploy the custom action into office 12.

Basically the workflow action will try to escalate anything to a person's manager using information stored in active directory, so that users in office 12 do not need to specify the manager.

The problem is, I don't know how to pass parameters into the workflow. I have the workflow book, but I can't really make sense to what is written the codes are in snippets.

[621 byte] By [KitKai] at [2007-12-21]
# 1

First of all you have to create parameters for your workflow. Select the workflow and a "Parameters" properties shows up in the property pane. You can create the parameters you need

When you start the workflow you have to pass in a parameter collection to the workflow. There is an example for this on Page 32 of the book "Presenting Windows Workflow Foundation"

DevinderSingh at 2007-9-10 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 2
But the example is for console app... When you host it in winapp, it seems to be significantly more complicated. And how do I get the parameters from my custom action?
LokeKitKai at 2007-9-10 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 3

Loke Kit Kai,

In Windows Workflow Foundation Help under Windows Workflow Foundation Tutorials there is a tutorial named: Creating Sequential Workflow

In the section "Creating the Host Application" you can find following sample code regarding passing parameters from a WinForms application:

private void submitButton_Click(object sender, EventArgs e)
{
Type type = typeof(Microsoft.Samples.Workflow.Quickstarts.SequentialWorkflow.ExpenseReportWorkflow);

// Construct workflow parameters
Dictionary<string, object> properties = new Dictionary<string, object>();
properties.Add("Amount", Int32.Parse(this.amount.Text));
properties.Add("Result", string.Empty);

// Start the workflow
workflowInstance = workflowRuntime.StartWorkflow(type, properties);
}

Regarding getting parameters from a custom activity you can take a look at this post: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=168365&SiteID=1

Also take in consideration that accessing workflow parameters directly from a custom activity is not a good design. You should have custom properties in your activity and you can assign them in workflow's Initialized event handler like this:

private void initialize(object sender, EventArgs e)

{

MyCustActivity.MyCustProp = Parameters["Amount"].Value;

}

ghenap at 2007-9-10 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 4

This is the scenario that I'm in.

Windows App that is hotsing a Generic Workflow:
This is a sequential workflow with a Custom PolicyActivity that can take in a RuleSet
and associated data in order for RuleSet to be evualated.

Getting the associated data to the custom PolicyActivity is not very clear.
I have to loop through records of a dataset to and evaluate its outcome. In some
cases I need data from multiple datasets. I want to keep the custom PolicyActivity generic so that other consuming application can make use of Windows Workflow.

So that in mind, I want to be able to host WWF within a Windows App so that any plugins that are developed to be hosted within this WinApp can make use of WWF as exposed thorough this WinApp.

I'm pretty new to the WF scene. I'm looking for ideas and suggestions on how I can pass data into Custom PolicyActivity and still keep the activity generic in that it should
take a ruleset and its accompanying data and run with it to produce a result.

Thanks,
Prabhu

pharita at 2007-9-10 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 5

I do not get parameter properties when I select properties by right clicking in the designer; what is the problem? Under "Activity" I do not get parameters as shown in some of the examples.

ManivakkamKrishnan at 2007-9-10 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 6

This has changed in later versions. You now need to create a public property on your workflow class (code behind). The names and types of the properties should match the name and types of the parameters you pass in the dictionary when you call CreateWorkflow.

Matt

MattMilner-Pluralsight at 2007-9-10 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 7

Hey Kit Kai,

Host :

1. Create a new generic Dictionary object that Dictionary<string,object>

2. Add a value to the dictionary object...param1.add(string,object)

  • string is the name of the parameter
  • object is the object to pass the workflow

3. Pass the dictionary object to the runtime while you are creating the workflow

Workflow :

1. Create a public property within the workflow which has the same name as the string value set for the dictionary object

BayerWhite at 2007-9-10 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 8

Devinder Singh wrote:

a "Parameters" properties shows up in the property pane.

Hi,Devinder

I can't find a "Parameters" properties in the property pane..

Why?

Regards!

metaza at 2007-9-10 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 9

See my post dated 6/16 on this thread. There is no properties item in the grid anymore, you create public properties on the workflow class.

Matt

MattMilner-Pluralsight at 2007-9-10 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 10

Hi,

I tried to add parameters to my workflow too but i couldn't find parameters in the properties windows.

i use visual studio 2005. does this mean that i can only enter them manually?

thanks

femig at 2007-9-10 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 11
The Parameters property when away some time ago. Now you need to add properties directly to the code file yourself. This can easily be done with snippets. Bring up the context menu in the code file where you want the property and choose Insert Snippet... To insert a property with dependency property choose Workflow / DependencyProperty - Property for both languages. For a property with variable choose Visual C# / prop in C# and Common Code Patterns / Properties and Procedures / Define a Property in VB.
TomLake-MSFT at 2007-9-10 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 12

I'm trying to do the same thing, but when i right-click on my code activity i don't have a parameters option in the properties window.

abuswell at 2007-9-10 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 13

Hi,

One more question regarding his post, I have a similar project, where I pass the dictionary with the parameters and the values are stored inside de properties of the workflow class, all works well.

The problem is that in another web form, I want to list thw running workflows and acces these properties, I can get to the point where I have the workflowInstance class, but How can I get the values of the properties from it? Thanks

llima at 2007-9-10 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 14
You can not access the property values from the workflow instance. Instead you will need to use tracking. Take a look at the post at http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1056239&SiteID=1 for more information.
TomLake-MSFT at 2007-9-10 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...

Software Development for Windows Vista

Site Classified