March 05, 2012

Creating SharePoint 2010 Workflows: Starting with Visual Studio 2010 Part 2

Building and Deploying



Go to the Build menu and select Deploy Solution. This generated code is called a workflow template; several instances of the same workflow template can be associated to the same list or to a different list in the site collection.


Go to your site, click the Expense Reports list, go to the list settings, and click the Workflow Settings button on the SharePoint Ribbon, as Figure 13 shows.


Figure 13: Workflow button
The Workflow Settings window appears. This window shows a list of available workflow templates. Our workflow template is available because it is encapsulated in a SharePoint feature with a scope of Site (a site collection); more about this later.
In this window, you can associate your workflow template with the current list.
We already have one association (performed by VS 2010), named Litware, as Figure 14 shows.ExpenseReports-ExpenseReportWorkflow, but you can create other workflow associations by clicking the Add a workflow hyperlink. (You can display the list of available workflow templates by clicking the drop-down arrow.)
Click the Litware.ExpenseReports-ExpenseReportWorkflow association link to view the workflow association settings, which Figure 15 shows. Note that the option is selected to start the workflow when a new item is created. Click OK.

Figure 14: Workflow association

Figure 15: Workflow association settings

Go to the Expense Report list and add a new item, as Figure 16 shows. Save this item. Because the workflow is configured to start when a new item is created, saving the item will cause a workflow instance to be created from our workflow template.


Figure 16: Adding a new list item
Indeed, if you go back to the list view, which Figure 17 shows, you will notice a new column that has the workflow association as a name. If you click the Completed hyperlink, you will visualize the workflow status, history, and tasks in the Workflow Information window, which Figure 18 shows.



Figure 17: Workflow Association column




Figure 18: Workflow Information window


Using Workflow Activities

A workflow is a set of steps; each step is an activity. Activities are .NET classes. We can reuse existing activities or create custom activities, as I will illustrate later.
The Workflow Foundation (WF) infrastructure is a set of assemblies that can be visualized in the References folder of our VS 2010 project (see Figure 19).
As part of the .NET Framework 3.5, WF provides several interesting activities that can be used in SharePoint. (Not all WF activities can be used in SharePoint, however.)
These activities are provided in the System.Workflow.Activities assembly, as Figure 19 shows.


Figure 19: Workflow assemblies to reference
The SharePoint team also provided more specific SharePoint activities, which you can find in the Microsoft.SharePoint.WorkflowActions assembly. This assembly can be found in the 14\ISAPI folder and is referenced by default in our VS 2010 project.
These activities can be dragged and dropped into the VS workflow design surface from the toolbox (select the SharePoint Workflow panel), which Figure 20 shows.


Figure 20: Workflow activities toolboxes




Just to make sure that our basic workflow can at least say "Hello World," we will drag and drop LogToHistoryListActivity to the workflow surface. Figure 21 shows the addition of an activity.
Now, in Workflow Designer, select logToHistoryActivity, go to its property page, and type "Hello World" in the HistoryOutcome property, as Figure 22 shows. Deploy the solution as you did previously (selecting Deploy Solution from the Build menu).



Figure 21: Adding an activity




Figure 22: LogToHistoryList activity properties

Go to the Expense Reports list. Select the expense report that you created earlier, and then click the Workflows button on the SharePoint Ribbon, as Figure 23 shows. The Start a New Workflow window, which Figure 24 shows, appears.
Click the Workflow button to start our workflow. Go to the workflow status, and you should see the Hello World message, as Figure 25 shows

No comments:

Post a Comment