Friday, February 11, 2011

Building an Employee Review workflow in SharePoint 2007 - Part 1

This blog post is a tutorial of building a workflow-based sample application in SharePoint 2007 using Workflow Foundation. This is the first part of this tutorial. To go Part 2, click here. This tutorial assumes you have a working knowledge of Visual Studio, C#, Workflow Foundation, InfoPath forms, and Microsoft Office SharePoint 2007. I would also assume that you either have a VM setup that you use to develop SharePoint projects or you have a test/dev server that you can remote into to perform work. For my development I prefer to use VirtualBox as my virtual machine software and run a virtual machine Windows Server 2003 R2 server with all the requirements for a single-installation SharePoint instance. Let's get started.

Step 1: We need to build out 3 Info Path forms: Initiation, Association, and Action forms

For the Association InfoPath form do the following:

  1. - Open InfoPath and click Design a Form Template
  2. - Select based on 'Blank' and click OK
  3. - Create a form name it Association.xsn
  4. - Go to the Design a Form Link on the right and goto 'DataSource'
  5. - Setup a name for your data source (FormFields)
  6. - Create some field names (User Name, Full Name, Review Type, Comments)
  7. - Goto Layout task and insert a custom table with 1 column and 3 row
  8. - Goto Controls task and uncheck 'Auto-create' datasource and then drag a textbox into the first two rows and a button in the last row
  9. - In the properties of the textboxes make sure their bindings match User Name and Full Name and then go into the button properties and create 2 actions
  10. - First action (Submit data using a data connection)
  11. - Add action ( click add, Create a new connection to: Submit Data, Next, To the hosting environment, Enter 'Submit', click finish.
  12. - Second action (Close this form: No Prompt)

Your form should look like this:

For the Initiation form follow these steps:
  1. - Open up Assocation.xsn again in design mode and save as... name it InitiationForm.xsn
  2. - Change the binding of the textbox to ReviewType and Comments
  3. - Save the form
Your form should look like this:

For the Action form follow these steps:
  1. - Follows the steps from the Association Form directions and create a new template called Action.xsn
  2. - Re-name the data source to actionFields and create these fields (reviewCompleted, reviewNotes) 
  3. - Set its data-type to boolean (True/False) for reviewCompleted
  4. - Set reviewNotes to Text field (string)
  5. - Copy the same Rules that you did for the button in the first form. (Submit using a data connection, Close the form)
  6. - Save the form and exit

Step 2: Add Item Schema

- Create an xml file called itemdata.xml
- Copy this xml into the file and save
- <z:row xmlns:z="#RowsetSchema"
       ows_Comment="" />
- Open up the Action.xsn form in design mode and goto Data Sources link
- Click Manage Data connections and go through the wizard and create a connection to receive data
- Select the XML document option and then browse to find the file, then on the next screen make sure the checkbox is checked concerning Auto-Retrieve data when form is opened, and use the default name, and click finish
- On the reviewNotes text box goto properties and set the formula (fx) to Insert Value or Group button and select ows_reviewComments node and click OK
- Save form and exit

Step 3:  Create a workflow project (Sequential Workflow)
  1. - Open Visual Studio 2008 and create a new project called EmployeeReview based off the SharePoint Server Sequential Workflow template
  2. - follow these steps if you get the error about deploying to the sharePoint site collection, you need to use the stsadm.exe tool to activate the Publishing feature in sharepoint (pain-in-my-butt!)
  3. - Also, make sure your path for the debug location just includes the http://sitename:portNumber
Step 4: Publish the Info Path forms
- We have to publish the forms to the server so inside of InfoPath you need to located the AssociationForm.xsn (or whatever you called the Association form) and goto Design Tasks
- Click 'Change Compatibility Settings'
- Check the box 'Design a Form Template That Can Be Opened in a Browser'
- Enter the URL of the InfoPath forms service (assuming you already started it, e.g. http://server/)
- Click Security and Trust and then uncheck 'Automatically Determine Security Level'
- Click Full Trust mode
- Click Create a Certificate and then OK.
- Go back to Design Tasks list and make sure that the Design Checker does not have any issues/problems
- Click 'Publish Form Template' and click browse, (make sure your path is the same path as where the workflow project in visual studio resides) find your AssociationForm.xsn and select it and click OK.
- Clear the next screen for 'alternate path access' and click OK
- Click 'Publish'
- Once complete, repeat for both other forms (InitiationForm.xsn, Action.xsn) and make sure to use the same certificate you created , there is no need to have multiple certificates unless specified

Step 5: Coding the workflow
- On the workflow1.cs , right-click and 'generate event handlers'
- Check your toolbox and make sure you have the SharePoint Workflow templates installed (VS2008 should already have them, VS2005 you might need to install them or point to them thru > Choose Toolbox Items > Complete Task, etc)

This has been a pretty long blog post and if you want to see how to code the rest of the workflow see Building an Employee Review workflow in SharePoint 2007 - Part 2

Wednesday, February 2, 2011

Tip #1: Get the Fab 40 SharePoint Templates

For many SharePoint installations, sometime the default installation templates are just too basic and need some help. Check out microsoft's fab 40 customized templates at the following link below:

These templates are based off the functionality only available for Windows SharePoint Services 3.0 however. They are still a great addition to your toolset!

Good luck!

Welcome to SharePoint 2007 Dev blog!

This is the first posting in a new series of blogs about SharePoint 2007 development, strategy, and exploration of the massive application platform. SharePoint 2007 is a huge upgrade from its predecessor with features that truly make it "Enterprise-Ready" software. Subscribe and stay tuned to this blog if you are interested in knowing more about SharePoint development, sales & strategy, and explorations in customizing SharePoint. Also, if you are interested in SharePoint consulting, please see our company blog at Vorality Consulting.