In this walkthrough I want to show you how to create a Sequential Workflow with Visual Studio 2010 for use in SharePoint 2010. – I will show how to create a custom Task Form for interaction with users. The Task form will be a native SharePoint list form. No InfoPath. There are many InfoPath samples out there but they cannot be used on a SharePoint Foundation 2010 platform. But workflows can be used on SharePoint Foundation 2010 too!

To reproduce the following steps you need to create a SharePoint site. – In the walkthrough I’ll use a Site Collection located at “http://sharepoint.local/sites/workflow”.

The “TemplateType” attribute represents the “Workflow History” list template. It resists on a SharePoint feature with ID “00BFEA71-4EA5-48D4-A4AD-305CF7030140”. It’s a native SharePoint feature.

You can add the attibute “Hidden” to the “ListInstance” tag and set it’s value to “TRUE” to hide the list as it’s done by SharePoint by default for this list. In this case you should also change “OnQuickLaunch” to “FALSE”. For my demo purpose I want to have “Workflow History” visible and on the Quick Launch bar.

5. Now we will create all tools we need for a “Workflow 1”. (May be I’ll create more workflow demos later. So it’s number 1.)

Use “Workflow 1 Tasks” as name of the list definition and “Tasks” as base type. Check “Add a list instance…”.

10. Now open “Elements.xml” of the new list definition project item.

We need to change the identifier of the list type we create! – It must be “107”. This is the list template ID for workflow tasks lists in SharePoint. The workflow designer will search for a list with this type inside the site where a new workflow will be created.

Here is the content of “Elements.xml” after our modification:

1:<?xmlversion="1.0"encoding="utf-8"?>

2:<Elementsxmlns="http://schemas.microsoft.com/sharepoint/">

3: <ListTemplate

4:Name="Workflow 1 Tasks"

5:Type="107"

6:BaseType="0"

7:OnQuickLaunch="TRUE"

8:SecurityBits="11"

9:Sequence="360"

10:DisplayName="Workflow 1 Tasks"

11:Description="Tasks of Workflow 1"

12:Image="/_layouts/images/itgen.png"/>

13:</Elements>

11. Now we modify the “Elements.xml” file of the list instance that will be created during deployment:

Here we also need to modify the type identifier to “107”. Furthermore we change the list url: “Lists/Workflow1Tasks”.

Here is the complete content of “Elements.xml”:

1:<?xmlversion="1.0"encoding="utf-8"?>

2:<Elementsxmlns="http://schemas.microsoft.com/sharepoint/">

3: <ListInstanceTitle="Workflow 1 Tasks"

4:OnQuickLaunch="TRUE"

5:TemplateType="107"

6:Url="Lists/Workflow1Tasks"

7:Description="Tasks of Workflow 1">

8: </ListInstance>

9:</Elements>

In a “real world” scenario we would prevent the list from being listed on the Quick Launch bar. So the corresponding parameter must be set to “FALSE”.

12. Now we need to modify the “Schema.xml” file of the list definition.

First we set the list type to “107” and configure some other attributes:

1:<Listxmlns:ows="Microsoft SharePoint"Title="Workflow 1 Tasks"

2:FolderCreation="FALSE"Direction="$Resources:Direction;"

3:EnableContentTypes="TRUE"VersioningEnabled="TRUE"

4:Url="Lists/Workflow1Tasks"

5:Type="107"BaseType="0"

6:xmlns="http://schemas.microsoft.com/sharepoint/">

7:[…]

Now remove the the content types defined in the “ContentTypes” tag in the “schema.xml” file.

15. Have a look into the site using the browser. – We will test our “Edit” form. Remember that we did not specify special “New” form or “Display” form. This you could do the same way as you created the “Edit” form.

We see our lists in the Quick Launch.

Open the “Workflow 1 Tasks” list. On the Ribbon open the “Items” tab. We see our Content Type in the New Item submenu:

Create an item of this type. You see a standard “New” form and on it you see our three “Test” fields:

Enter some data and press “Save”.

Open the item in “Edit” form. Now you should see our custom list form.

If you click “Save As Draft” your changes will be stored in the task item. If you click “Complete Task” two item fields will be changed in addition to the changes made in the form: It sets “Status” to “Tasks_Completed” and “% Complete” to “100”. You can see this in the Code Behind file of the list form.

Test all buttons.

After “Complete Task”:

You see: “% Complete” is set to “100 %”.

So far our projects works as expected.

See Part 2 for the next steps… There I will show you how to create a simple Sequential Workflow that uses our Task Form.

In this walkthrough I want to show you how to create a Sequential Workflow with Visual Studio 2010 for use in SharePoint 2010. – I will show how to create a custom Task Form for interaction with users. The Task form will be a native SharePoint list form. No InfoPath. There are many InfoPath samples out there but they cannot be used on a SharePoint Foundation 2010 platform. But workflows can be used on SharePoint Foundation 2010 too!

To reproduce the following steps you need to create a SharePoint site. – In the walkthrough I’ll use a Site Collection located at “http://sharepoint.local/sites/workflow”.

16. Now we need to add a list that we use to connect a workflow with. We create a “List Definition” project item named “Workflow 1 Host List”.

We change the “Elements.xml” file of the List Instance project item.

We change the Title, URL and Description.

17. Deploy the project.

18. Now we start creating a Sequential Workflow.

Create a “Sequential Workflow” project item named “Workflow 1”.

Create the workflow as “List Workflow”.

You will see all the lists we created in the previous steps. Remember: You have to (successfully) deploy the project before you can use the lists that will be created during deployment. – Without previous deployment the wizard may fail before you see the following dialog page.

In the first dropdown list choose “Workflow 1 Host List”. All other lists should be selected automatically because there is only one usable list of every needed type.

19. We will add a “Create Task With Content Type” workflow activity that will use our “Workflow 1 Task 1” we created in the steps 1 to 15 (blog post “part 1”).

Open the “Toolbox” pane and drag “CreateTaskWithContentType” into the Workflow Designer.

After you did this you get:

Now we need to configure the workflow activity in the “Properties” pane.

Set “correlationToken” to “task1” and the sub element of “correlationToken” named “OwnerActivityName” to “Workflow_1”.

Now we need to create code behind properties for some activity properties. As example I’ll show how to create a code behind property for “ContentTypeId”.

Click on the Button “…” at the activity property edit box:

In the dialog select the tab “Bind to a new member”. Enter the name “New member name” and select the “Create Property” radio button. Press “OK”.

Here are the property bindings you need to create:

“ContentTypeId” = “task1ContentTypeId”

“TaskId” = “task1Guid”

“TaskProperties” = “task1Properties”

In “MethodInvoking” type “createTask1Invoke” and press ENTER. – You’ll be directed to the code editor.

(The activity properties look like this after you finished: )

In the method we initialize the task1-Properties we created before. The “ContentTypeId” is taken from the “Schema.xml” file of our “Workflow 1 Tasks” list where we created the Content Type “Workflow 1 Task 1”.

After that your method looks like this:

20. Back in the workflow designer. We drag a “While” activity from the Toolbox pane into the workflow behind the “Create Task” activity.

Into the “While” activity we drag a “Sequence” property from the Toolbox pane. We get:

Into the “Sequence” activity we drag a “OnTaskChanged” activity from the Toolbox pane. We get:

Now we edit the properties of the created “OnTaskChanged” activity. We have to set the “CorrelationToken” as described above. Additionally we specify new property bindings:

“AfterProperties” = “task1Changed1_AfterProperties”

“BeforeProperties” = “task1Changed1_BeforeProperties”

“TaskId” => Bind to the existing member “task1Guid”!!!

In the “Invoked” property add the method name “task1Changed1Invoke”. – The code editor will be opened.

(The activity properties look like this after you finished: )

21. In the code we add a property at class level:

This property we set inside the “OnWorkflowItemChanged” activity. It will contain the information whether the Workflow Task Item we created before was “Completed” by the assigned user.

In the “task1Changed1Invoke” method we set the “isFinished” property.

22. Now we need to specify the condition for the “While” activity. In the workflow designer select this activity. In the “Condition” property select “Code Condition” and expand the property. Enter “while1Invoke” in the subproperty with (the same) name “Condition”.

In the code editor enter the code for “while1Invoke” like this:

The “e.Result” property has to be “TRUE” as long as the while loop should run. It should not run anymore (“e.Result = false”) if “isFinished” is TRUE.

23. In the workflow designer add a “CompleteTask” activity behind the “While” activity. Drag the “CompleteTask” activity from the Toolbar pane into the workflow designer. We get:

Select the “completeTask1” activity and edit it’s properties in the Property pane.

Bind “TaskId” to the existing member “task1Guid”

Create a new member namend “task1Outcome” for binding to “TaskOutcome”

DISCLAIMER

The informations on my blog are provided as is and I cannot guarantee that editing the registry or executing the provided code or provided scripts or doing other actions described in my articles will not cause serious damage. You use this information at your own risk! - I'm not responsible content on external sites.