How to: Create a Workflow for Workflow Manager 1.0
Updated: May 15, 2013
In this step of the Getting Started Tutorial, a workflow is created that uses the GetProducts
activity to return a collection of products. The workflow iterates through the collection and extracts the product name for each returned product, adds it to a list, and sets a user status containing the name of the product. This status is read and displayed by the workflow client application, which is created in a subsequent tutorial step. After all products have been read, the workflow sets a user status containing the list of product names, and completes.
Note
To watch a video walkthrough, or download the starter files and a completed version of the tutorial, see Workflow Manager 1.0 - Getting Started Tutorial.
In this Tutorial Step
Create the Workflow
Create the Arguments and Variables
Add the Workflow Activities
Create the Workflow
Open the solution from the previous step in the tutorial, How to: Create a Custom Activity, if it is not already open in Visual Studio 2012.
Right-click GetProductsActivities in Solution Explorer and choose Add, New Item.
In the Installed, Visual C# Items node, select Workflow. Select Activity from the Workflow list.
Type
GetProductsWorkflow
into the Name box and then click Add.Double-click GetProductsWorkflow.xaml in Solution Explorer to display it in the designer if it is not already displayed.
Drag a Sequence activity from the Control Flow section of the Toolbox and drop it onto the Drop activity here label of the workflow designer.
Create the Arguments and Variables
Click Arguments in the lower-left side of the activity designer to display the Arguments pane.
Click Create Argument.
Type
SearchKeyword
into the Name box, select In from the Direction drop-down list, and select String from the Argument type drop-down list.Click Arguments in the lower-left side of the activity designer to close the Arguments pane.
Click Variables in the lower-left side of the activity designer to display the Variables pane.
Click Create Variable.
Tip
If Create Variable is not displayed, click the Sequence activity in the workflow designer to select it.
Type
ProductsData
into the Name box, and select Browse for Types from the Variable type drop-down listType
DynamicValue
in the Type Name box, select DynamicValue from the results list, and click OK.Click Create Variable.
Type Count into the Name box, and select Int32 from the Variable type drop-down list.
Click Create Variable.
Type
ProductsList
into the Name box, and select String from the Variable type drop-down list.Click Variables in the lower-left side of the workflow designer to close the Variables pane.
Add the Workflow Activities
Drag a GetProducts activity from the GetProductsActivities section of the Toolbox and drop it in the Sequence activity, and configure the following properties.
Property Value ProductsData ProductsData SearchKeyword SearchKeyword Drag a CountDynamicValueItems activity from the DynamicValue section of the Toolbox and drop it on the Sequence activity so that it follows the GetProducts activity, and configure the following property values.
Property Value Result Count Source ProductsData Drag a SetUserStatus from the Runtime section of the Toolbox and drop it so that it follows the newly added CountDynamicValueItems activity, and specify the following expression for the Description property.
"Products: " + Count
Drag a Delay activity from the Primitives section of the Toolbox and drop it so that it follows the newly added SetUserStatus activity, and specify the following expression for the Duration property. The delay allows the workflow client to retrieve the status before the workflow sets the next status, and is added for the purposes of this tutorial. In a production application techniques such as using messaging activities or writing records to a database would be used to transfer information.
TimeSpan.FromSeconds (1)
Drag a While activity from the Control Flow section of the Toolbox and drop it so that it follows the newly added SetUserStatus activity.
Click Variables in the lower-left side of the activity designer to display the Variables pane.
Click Create Variable.
Type
Items
into the Name box, select Int32 from the Variable type drop-down list, ensure that While is selected in the Scope drop-down list, and type0
in the Default box.Click Create Variable.
Type
ProductName
into the Name box, select String from the Variable type drop-down list, and ensure that While is selected in the Scope drop-down list.Click Variables in the lower-left side of the activity designer to close the Variables pane.
Type the following expression in the Condition box of the While activity.
Items < Count
Drag a GetDynamicValueProperty<T> activity from the DynamicValue section of the Toolbox and drop it on the Body of the While activity.
In the Select Types window that appears once the activity is dropped, select String from the drop-down list, and click OK.
Click the GetDynamicValueProperty<T> activity in the workflow designer to select it, and configure the following properties.
Property Value DisplayName GetProductName PropertyName "(" + Items + ")/ProductName" Result ProductName Source ProductsData Drag a SetUserStatus from the Runtime section of the Toolbox and drop it on the While activity so that it follows the newly added GetDynamicValueProperty<T> activity, and specify the following expression for the Description property.
"Product: " + ProductName
Note
Note that when the SetUserStatus is dropped, an enclosing Sequence activity is added that contains both the GetDynamicValueProperty<T> activity and the SetUserStatus activity.
Drag a Delay activity from the Primitives section of the Toolbox and drop it so that it follows the newly added SetUserStatus activity, and specify the following expression for the Duration property. The delay allows the workflow client to retrieve the status before the workflow sets the next status, and is added for the purposes of this tutorial.
TimeSpan.FromSeconds (1)
Drag an Assign activity from the Primitives section of the Toolbox and drop it so that it follows the newly added Delay activity, and configure the following properties.
Property Value To Items Value Items + 1 Drag a second Assign activity from the Primitives section of the Toolbox and drop it so that it follows the first Assign activity, and configure the following properties.
Property Value To ProductsList Value ProductsList + ProductName + "\n" Drag a SetUserStatus from the Runtime section of the Toolbox and drop it so that it follows the While activity as the last activity in the outer Sequence, and specify the following expression for the Description property.
"Products List:\n" + ProductsList
Note that the user status is limited to 255 characters, and any characters beyond 255 are truncated.
Press Ctrl+Shift+B to build the solution.
To see an example of the completed workflow, and a video walkthrough of this tutorial step, see Workflow Manager 1.0 - Getting Started Tutorial
For instructions on how to create a publish and run the workflow, see the next step in the tutorial, How to: Publish and Run a Workflow.