Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

Developing Sequential Workflows for SharePoint Server 2007 Using Visual Studio 2008

SharePoint 2007

Summary: Learn to use Microsoft Visual Studio 2008 to create a Microsoft Office SharePoint Server 2007 sequential workflow with associated forms and content types to manage headcount request approvals. (31 printed pages)

Joel Krist, Akona Systems

August 2008

Applies to: Microsoft Office SharePoint Server 2007, Microsoft Office InfoPath 2007, Microsoft Visual Studio 2008

Contents

Download the sample code that accompanies this article: HeadCount Request Workflow Sample Code

The Headcount Request Approval Workflow Solution

A common scenario in many organizations involves the request to open a new job position. The process typically is something like this:

  1. A hiring manager decides there is justification to open a new position, and submits a new headcount request for approval.

  2. Senior management reviews the headcount request and either approves or denies it.

  3. If the headcount request is approved, a new position is opened so that the recruiting process can begin.

This article presents a Headcount Request Approval workflow solution that makes use of the workflow capabilities of Microsoft Office SharePoint Server 2007. You can use this workflow solution to help manage the headcount request approval process. The solution uses Microsoft Visual Studio 2008 to create the following:

  • A custom Microsoft Office InfoPath 2007 form that hiring managers can use to submit headcount requests.

  • A SharePoint sequential workflow that manages the state of the headcount request, assigns headcount request tasks, and sends notifications to the employees involved in the approval process.

  • Two SharePoint custom content types that are used to display headcount request-specific task editing forms.

  • A class library that implements two custom .aspx pages for the Headcount Request Workflow's association and initiation forms.

Headcount Request Scenario

The headcount request scenario this article walks you through includes the following four actions:

The following sections describe these actions.

Associating the Workflow with the Document Library

One of the key pieces of the headcount request approval solution is an Office SharePoint Server 2007 document library that is used to store Office InfoPath 2007 Headcount Requests forms. The Headcount Request Workflow needs to be associated with the document library before the workflow can be run against form instances in the document library.

The Headcount Request Workflow uses an ASP.NET .aspx page for its association form. The association form is displayed to the user who is associating the workflow with the document library, and allows that user to specify the default settings for the workflow. Figure 1 shows the Headcount Request Workflow association form.

Figure 1. Headcount Request Workflow association form

Headcount Request Workflow association form

The form contains three groups of settings:

  • Workflow Tasks This single workflow task setting determines how headcount request approval tasks are assigned to members of the senior leadership team. The choices are parallel and serial assignment. If All participants simultaneously (parallel) is selected, headcount request review tasks are assigned to all specified senior leadership team members at the same time. If One participant at a time (serial) is selected, headcount request review tasks are assigned to senior leadership team members one after the other, in the order that their names are listed.

  • Senior Leadership Team Settings These settings include the names of the senior leadership team members who can approve headcount requests, a message to display to reviewers, and the number of approvals required for the headcount request.

  • Operations Team Settings These settings include the names of the operations team members who can open a new position for an approved headcount request and a message to display to them.

Submitting a Headcount Request

The headcount request approval process begins when a hiring manager decides there is business justification to request headcount. To start the request approval process, the manager opens the Headcount Requests SharePoint document library and chooses to create a request. The Headcount Requests document library is configured to use the Form content type, with its document template set to the custom Office InfoPath 2007 Headcount Request form.

Figure 2. Creating a headcount request

Creating a headcount request

The Office InfoPath Headcount Request form is a browser-compatible form template that is uploaded and activated on the site that contains the Headcount Requests document library. This allows the form to be hosted in the browser by InfoPath Forms Services.

Figure 3. Office InfoPath Headcount Request form

Headcount Request InfoPath form

The hiring manager fills in the Headcount Request form, and then clicks Save and Close. The form template uses managed code to generate a unique name by concatenating the values from the Team and Date fields with the current time. It then saves the form to the Headcount Requests document library.

Starting the Headcount Request Workflow

The Headcount Requests document library is associated with a SharePoint sequential workflow. The workflow is configured to allow it to be started manually on items in the document library. The hiring manager pauses the mouse over the previously saved Headcount Request form in the Headcount Requests document library, and on the menu clicks Workflows.

Figure 4. Selecting Workflows menu item

Selecting the Workflows menu item
Cc811589.note(en-us,office.12).gifVisual Basic Note:

The workflow could be configured to start automatically on creation of headcount requests. However, to demonstrate the use of the workflow initiation form, this walkthrough assumes that the workflow is not configured to start automatically.

The Headcount Requests Workflows page is displayed, allowing the manager to start an instance of the Headcount Request Workflow on the Headcount Request form. The manager selects the Headcount Request Workflow.

Figure 4a. Selecting the Headcount Request Workflow

Selecting the Headcount Request Workflow

The Headcount Request Workflow uses an ASP.NET .aspx page as its initiation form. When an instance of the Headcount Request Workflow is started manually, the workflow initiation form is displayed. This allows the initiating user to override the default workflow settings that were specified when the workflow was associated with the document library. The workflow initiation form is very similar to the workflow association form. It differs only in that it offers no option for specifying parallel or serial assignment of headcount request review tasks.

Figure 5. Headcount Request Workflow initiation form

Headcount Request Workflow initiation form

The user who starts the workflow can choose whether to modify the default settings, and then clicks OK to start the workflow. The Headcount Requests document library now shows the Headcount Request Workflow status as In Progress on the headcount request.

Figure 6. Headcount Request Workflow in progress

Headcount Request Workflow in progress

Clicking the In Progress link for the workflow displays the Workflow Status page (Figure 7). This page shows the currently assigned tasks and workflow history.

Figure 7. Headcount Request Workflow Status page

Headcount Request Workflow initial status

The status page also shows that the workflow has sent an e-mail message to the person specified in the Reports To field on the Headcount Request form, and the person who initiated the workflow (in this case, the person is the same), to let both know that the workflow has started. The Workflow Started e-mail message, shown in Figure 8, contains headcount request information pulled from the form and a link to the Workflow Status page.

Figure 8. Workflow Started e-mail message

Workflow Started e-mail message

Completing Headcount Request Workflow Tasks

In addition to sending workflow started e-mail messages, the workflow has assigned tasks to the senior leadership team members specified on the workflow initiation form, and has sent them a notification e-mail message that lets them know they have a headcount request to review. The task notification e-mail message contains headcount request information pulled from the form, the senior leadership team instructions specified on the workflow initiation form, and a link to a form that the reviewer can use to approve or deny the request.

Figure 9. Workflow Approval task notification e-mail message

Workflow Approval task notification e-mail message

The approver clicks the link in the e-mail message. A custom workflow task edit form opens in which the approver can approve or deny the request. Clicking either Approve or Deny (see Figure 10) marks the task as completed.

Figure 10. Headcount Request Review task edit form

Headcount Request Review task edit form

The workflow tracks the number of approved and denied headcount request approval tasks. If all approval tasks are completed and the required number of approvals has not been reached, the workflow sends an e-mail message to the person specified in the request form's Reports To field and to the workflow initiator. This message lets them know that the headcount request was denied. As soon as the required number of approvals is reached, the workflow moves to the next stage. In this stage, tasks are assigned to the specified operations team members so that they know to open a position for the headcount request. Figure 11 shows the Workflow Status page when the required number of approvals is reached.

Figure 11. Headcount Request Workflow approved status

Headcount Request Workflow approved status

As shown in Figure 12, the e-mail message that is sent to the specified operations team members contains headcount request information pulled from the request form, the operations team instructions from the workflow initiation form, and a link to a form that the team member can use to save the position number.

Figure 12. Workflow Position Number task notification e-mail message

Workflow Position Number task notification e-mail

The operations team member opens the position, generates a position number, and then clicks the link in the e-mail message. A headcount request position form opens in which the operations team member can add the position number to the original headcount request. The team member then clicks Save.

Figure 13. Headcount Request Position Number task edit form

Headcount Request Position Number task edit form

The workflow saves the position number to the original Headcount Request form, as shown in Figure 14.

Figure 14. Headcount Request Workflow completed status

Headcount Request Workflow completed status

The workflow then sends a workflow completed e-mail message to the person specified in the request form's Reports To field and to the workflow initiator, to inform them that the headcount request is completed and whether the request was approved. Then, the workflow ends.

Figure 15. Workflow Completed e-mail message

Workflow Completed e-mail message

Solution Implementation Details

The Headcount Request Approval solution was created with Visual Studio 2008. The following sections provide details about the implementation of the solution's components.

Headcount Request InfoPath Form

The headcount request InfoPath form that is used to submit new headcount requests is a browser-enabled form template that allows InfoPath Forms Services to host it. Hosting the form in the browser removes the requirement that users have the InfoPath client installed, and simplifies the deployment and update processes.

The Headcount Request form has two views:

  • A primary view that users interact with when submitting headcount requests

  • A debugging view that can be used to view debug messages generated by the form code during processing

The Headcount Request form uses managed code to generate a unique form name when saving a form to the Headcount Requests document library. It handles the form's Loading event and determines the location to save the file to, based on whether a new or existing form is being loaded. The location to save to is stored in the FormState dictionary for later use.

private object _strSaveLocation 
{
    get { return FormState["_strSaveLocation"]; }
    set { FormState["_strSaveLocation"] = value; }
}

public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
    ClearDebugMessages();

    // See if the form was opened in the browser. If so, and it is a new
    // form, we get the location to save to from the 
    // "SaveLocation" parameter. Else, we get it from the 
    // "Source" parameter. If the form was opened in the client, we 
    // get the Uri from the form template.

    if (Application.Environment.IsBrowser)
    {
        try
        {
            // If this is a new form, the input parameters will contain 
            // the SaveLocation parameter value. If not, this will 
            // throw an exception that means this is an existing form.
            _strSaveLocation = 
                e.InputParameters["SaveLocation"].ToString();
            WriteDebugMsg("This is a new form. SaveLocation = " +
                _strSaveLocation);
        }
        catch
        {
            // This is an existing form. Get the save location from the
            // base part of the Source parameter value.
            string strSource = e.InputParameters["Source"].ToString();
            _strSaveLocation =
                strSource.Substring(0, strSource.IndexOf("Forms") - 1);
        }
    }
    else
        _strSaveLocation = this.Template.Uri.ToString();
}

The Click event for the Save button and Close button is handled to perform the saving of the form. The code in the click handler determines if a new or existing form is being saved, and generates a unique file name if needed. It then uses of the form's Submit to Document Library data connection to save the form.

public void btnSaveAndClose_Clicked(object sender, ClickedEventArgs e)
{
    try
    {
        // Check whether this is an existing form by checking the
        // form's Uri property to determine if it is equal to "New Form". 
        // If it is, this is a new form instance being saved for the 
        // first time. Else, it's an existing form in a SharePoint list 
        // that is being saved again.
                
        string infoPathFileName = string.Empty;

        if (this.Uri == "New Form")
        {
            // This is a new form; generate a file name by concatenating 
            // the Position and Team fields with the current date/time.

            XPathNavigator xpathNavigator = this.CreateNavigator();
            string teamPart =
                xpathNavigator.SelectSingleNode(
                    "/my:HeadcountRequestFields/my:Team",
                    this.NamespaceManager).Value;

            string dateTimePart = FormatDateTime(DateTime.Now);
                     
            infoPathFileName = teamPart + dateTimePart;
            infoPathFileName = infoPathFileName.Replace(" ", ""); 

            WriteDebugMsg("This is a new form named " + 
                infoPathFileName);
        }
        else
        {
            // This is an existing form; reuse the form's name.
            string url = this.Uri;
            int startIndex = url.LastIndexOf("/") + 1;
            int length = url.Length - startIndex;

            infoPathFileName =
                System.Uri.EscapeDataString(
                    url.Substring(startIndex, length));

            WriteDebugMsg("This is an existing form named " +
                infoPathFileName);
        }

        if (infoPathFileName != string.Empty)
        {
            // Use the "Submit to Document Library" data connection
            // to save the form.
            FileSubmitConnection fileSubmitConnection =
               (FileSubmitConnection)(this.DataConnections["Submit to Document Library"]);

            WriteDebugMsg("Save Location: " + _strSaveLocation);

            fileSubmitConnection.FolderUrl =
                _strSaveLocation.ToString();
            fileSubmitConnection.Filename.SetStringValue(
                infoPathFileName);
            fileSubmitConnection.Execute();

            WriteDebugMsg("Form submitted to " +
                fileSubmitConnection.FolderUrl);
        }
    }
    catch (Exception ex)
    {
        WriteDebugMsg(ex.Message);                
    }
}

The following table lists key Headcount Request form template files and folders.

Table 1. Key Headcount Request form template files and folders

FileDescription

HeadcountRequestIPForm

Sample code folder that contains the project file and source code for the Headcount Request form.

HeadcountRequisition.xsn

Published InfoPath Headcount Request form template, located in the HeadcountRequest\HeadcountRequestIPForm\Published sample folder.

FormCode.cs

Managed code file for the Headcount Request form template.

Headcount Request Workflow Association Form and Initiation Form

The Headcount Request Workflow association form and initiation form allow users to specify the workflow settings when associating the workflow with the Headcount Requests document library, and when starting the workflow on a Headcount Request form.

The workflow association form and initiation form are implemented as ASP.NET .aspx pages in a class library named HeadcountRequestAspxPages.dll. The association form and initiation form classes derive from the same base class, HeadcountRequestWFDataPages, which is derived from the Microsoft.SharePoint.WebControls.LayoutsPageBase class. The HeadcountRequestWFDataPages base class implements methods for serializing form data to and from an XML string.

The following table lists key Headcount Request Workflow association form and initiation form files and folders.

Table 2. Key Headcount Request Workflow association form and initiation form files and folders

FileDescription

HeadcountRequestAspxPages

Sample code folder that contains the project file and source code for the Headcount Request Workflow association form and initiation form.

HeadcountRequestWFAssoc.aspx

Workflow association form.

HeadcountRequestWFAssoc.cs

Workflow association form code-behind file.

HeadcountRequestWFInit.aspx

Workflow initiation form.

HeadcountRequestWFInit.cs

Workflow initiation form code-behind file.

HeadcountRequestWFDataPages.cs

Code file for the HeadcountRequestWFDataPages base class that the association form and initiation form classes derive from.

FormData.cs

Code file for the FormData class, which is used when serializing data to and from the workflow forms.

Headcount Request Workflow

The Headcount Request Workflow is a SharePoint sequential workflow that is responsible for assigning tasks and sending notification e-mail messages to workflow participants.

The workflow has two phases:

  • The reviewer phase, during which senior leadership team members are assigned review tasks

  • The position number phase, during which operations team members are assigned tasks

Figure 16 shows the reviewer phase.

Figure 16. Workflow reviewer phase

Workflow reviewer phase

The reviewer phase of the workflow uses a replicator activity to create and assign headcount request review tasks to senior leadership team members. The replicator is initialized with the names of each of the senior leadership team members. The list of reviewers is generated in the OnWorkflowActivated.Invoked method by deserializing the data from the workflow initiation form into a FormData object.

private void onWorkflowActivated_MethodInvoking(object sender,
    ExternalDataEventArgs e)
{
    workflowId = workflowProperties.WorkflowId;
    
    // Helper defined in FormData.cs
    FormData data = 
        Helper.DeserializeFormData(workflowProperties.InitiationData); 

    this.reviewers = data.GetReviewers();
    this.opsTeamMembers = data.GetOpsTeamMembers();
    serialExecution = data.CreateTasksInSerial;
    reviewerDescription = data.Description;
    opsTeamDescription = data.OpsTeamDescription;
    requiredApprovalCount = data.RequiredApprovalCount;

    historyDescription = "Workflow started.";
}


Then, the list of reviewers is used to initialize the InitialChildData property of the replicator activity.

private void OnApproverTaskReplicatorInitialized(object sender,
    EventArgs e)
{
    approverTaskReplicator.InitialChildData = reviewers;

    if (serialExecution)
        approverTaskReplicator.ExecutionType = ExecutionType.Sequence;
    else
        approverTaskReplicator.ExecutionType = ExecutionType.Parallel;
}

The reviewer phase uses an OnTaskCreated activity as part of the replicator sequence to send a notification e-mail to each reviewer. It then waits for the task to complete, which happens when a reviewer approves or denies the request. The replicator uses a code condition for its UntilCondition property to determine when it should end. The approvalPhaseFinished method checks whether the required number of approvals has been reached or if all reviewers have completed their tasks. It returns true if the replicator should end, or false if it should continue.

private void approvalPhaseFinished(object sender,
    ConditionalEventArgs e)
{
    if(currentApprovalCount + currentDenialCount == reviewers.Length ||
        currentApprovalCount >= requiredApprovalCount)
        e.Result = true;
    else
        e.Result = false;
}

The workflow uses a code activity to send an e-mail message to the person specified in the Reports To field on the headcount request and to the person initiating the workflow, to let them know that the request is being processed. A code activity is used rather than a SendEmail activity because of the desire to generate a custom e-mail message that includes headcount request details from the original request form. The same e-mail generation code is used to create the task notification e-mail messages, and makes use of the HeadcountRequestFields class to get the contents of the original Office InfoPath Headcount Request form. The XML Schema Definition Tool (xsd.exe) was used to generate the HeadcountRequestFields class, by running the tool against the Headcount Request form schema.

The position number phase of the workflow also uses a replicator to assign tasks and send e-mail messages to the specified members of the operations team. Figure 17 shows the position number phase.

Figure 17. Workflow position number phase

Workflow position number phase

The position number phase first checks whether the required number of approvals has been reached and, if so, uses a replicator to assign tasks. The replicator sequence uses a CreateTaskWithContentType activity to create the tasks so that the custom task edit form for operations team members will be displayed when members edit their assigned task. For more information about the content types used by the Headcount Request Workflow, see Headcount Request SharePoint Content Types . As soon as a position number task is complete the replicator ends, allowing the workflow to end after sending workflow completed e-mail messages to the workflow originator and the contact specified as the Reports To person on the Headcount Request form.

The following table lists key Headcount Request Workflow files and folders.

Table 3. Key Headcount Request Workflow files and folders

FileDescription

HeadcountRequestWorkflow

Sample code folder that contains the project file and source code for the Headcount Request Workflow.

Workflow1.cs

Primary code file for the workflow; contains the core workflow functionality.

FormData.cs

Code file for the FormData class, which is used when serializing data to and from the workflow forms.

HeadcountRequestIPFormFields.cs

Code file for the HeadcountRequestFields class, which is used to access to the contents of the Office InfoPath Headcount Request form.

Feature.xml

Workflow.xml

Headcount Request SharePoint Content Types

The Headcount Request Workflow uses two custom SharePoint content types to support custom workflow task editing forms: the Leadership Team Task Workflow content type, and the Operation Team Task Workflow content type. The custom editing forms for the content types are implemented as ASP.NET .aspx pages, and provide the ability for headcount request reviewers to approve or deny requests, and for operations team members to save the position number for an approved headcount request.

Leadership Team Task Workflow Content Type

The leadership team task workflow content type is the default task list content type for the Headcount Request Workflow. The following XML fragment from the workflow's workflow.xml file shows the TaskListContentTypeId attribute being set to the unique identifier of the leadership team task workflow content type.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Workflow
    Name="Headcount Request"
    Description="This workflow faciliates the headcount request process."
    Id="5F837DB9-D8DB-4fae-99B2-4F90197A64FA"
    CodeBesideClass="HeadcountRequestWorkflow.HeadcountRequest"
    CodeBesideAssembly="HeadcountRequestWorkflow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8d9307eae9226f19"
  TaskListContentTypeId="0x01080100B33A350590D5455d81349D3111832B46"
...


The following XML is from the LeadershipTeamTaskWFCT.xml file used to define the leadership team task workflow content type.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ContentType  ID="0x01080100B33A350590D5455d81349D3111832B46"
    Name="LeadershipTeamTaskWorkFlowContentType"
    Group="Headcount Request Workflow"
    Description="Create a Custom Workflow Task for the Senior Leadership team."
    Version="0"
    Hidden="TRUE">
    
    <FieldRefs>
      <FieldRef ID="{83A82827-EC2D-46ce-A6CF-A68D6849B725}"
        Name="HeadcountRequestReviewerComments"
        DisplayName="Headcount Request Reviewer Comments"/>
      <FieldRef ID="{732AB06C-DE4B-4c70-88CF-7934C4AAF0DE}"
      Name="HeadcountRequestApproved"
      DisplayName="Headcount Request Approved"/>
    </FieldRefs>  

    <XmlDocuments>
      <XmlDocument
NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
        <FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
          <Edit>_layouts/LeadershipTeamTaskWFCT.aspx</Edit>
        </FormUrls>
      </XmlDocument>
    </XmlDocuments>
  </ContentType>

  <Field ID="{83A82827-EC2D-46ce-A6CF-A68D6849B725}"
    Name="HeadcountRequestReviewerComments"
    SourceID="http://schemas.microsoft.com/sharepoint/v3"
    StaticName="HeadcountRequestReviewerComments"
    Group="Headcount Request Workflow"
    Type="Note"
    DisplayName="Headcount Request Reviewer Comments">
  </Field>

  <Field ID="{732AB06C-DE4B-4c70-88CF-7934C4AAF0DE}"
    Name="HeadcountRequestApproved"
    SourceID="http://schemas.microsoft.com/sharepoint/v3"
    StaticName="HeadcountRequestApproved"
    Group="Headcount Request Workflow"
    Type="Text"
    DisplayName="Headcount Request Approved">
  </Field>
</Elements>

The markup in the LeadershipTeamTaskWFCT.xml file specifies the following about the leadership team task workflow content type:

  • It inherits from the SharePoint workflow task content type by specifying 0x010801 for the base part of its content type identifier.

    <ContentType  ID="0x01080100B33A350590D5455d81349D3111832B46"
    
    
  • It specifies that the LeadershipTeamTaskWFCT.aspx file, located in the _layouts folder, provides the content type's edit form.

    <FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
      <Edit>_layouts/LeadershipTeamTaskWFCT.aspx</Edit>
    </FormUrls>
    
    
  • It references two columns, also defined in the LeadershipTeamTaskWFCT.xml file: one for storing comments from reviewers, and one for storing whether the request was approved.

       <FieldRefs>
         <FieldRef ID="{83A82827-EC2D-46ce-A6CF-A68D6849B725}"
           Name="HeadcountRequestReviewerComments"
           DisplayName="Headcount Request Reviewer Comments"/>
         <FieldRef ID="{732AB06C-DE4B-4c70-88CF-7934C4AAF0DE}"
           Name="HeadcountRequestApproved"
           DisplayName="Headcount Request Approved"/>
       </FieldRefs>  
    
    

Operations Team Task Workflow Content Type

The operations team task workflow content type is referenced when the position number phase of the Headcount Request Workflow creates tasks for the operations team members with the CreateTaskWithContentType activity. This allows the custom task edit form to be displayed. The operations team task workflow content type identifier is specified for the value of the ContentTypeId property of the CreateTaskWithContentType activity, as shown in Figure 18.

Figure 18. CreateTaskWithContentType activity ContentTypeId property

Activity showing ContentTypeId property

The following XML is from the OpsTeamTaskWFCT.xml file used to define the operations team task workflow content type.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ContentType  ID="0x010801006439AECCDEAE4db2A422A3A04C79CC83"
    Name="OpsTeamTaskWorkFlowContentType"
    Group="Headcount Request Workflow"
    Description="Create a Custom Workflow Task for the Operations team."
    Version="0"
    Hidden="TRUE">

    <FieldRefs>
      <FieldRef ID="{7B37146C-B563-411b-B004-9740C8E2C272}"
        Name="HeadcountRequestOpsComments"
        DisplayName="Headcount Request Ops Comments"/>
      <FieldRef ID="{10414189-35AD-40b3-AF50-740ACAD91246}" 
        Name="HeadcountRequestPositionNumber"
        DisplayName="Headcount Request Position Number"/>
    </FieldRefs>
  
    <XmlDocuments>
      <XmlDocument
NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
        <FormUrls
xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
          <Edit>_layouts/OpsTeamTaskWFCT.aspx</Edit>
        </FormUrls>
      </XmlDocument>
    </XmlDocuments>
  </ContentType>

  <Field ID="{7B37146C-B563-411b-B004-9740C8E2C272}"
    Name="HeadcountRequestOpsComments"
    SourceID="http://schemas.microsoft.com/sharepoint/v3"
    StaticName="HeadcountRequestOpsComments"
    Group="Headcount Request Workflow"
    Type="Note"
    DisplayName="Headcount Request Ops Team Member Comments">
  </Field>

  <Field ID="{10414189-35AD-40b3-AF50-740ACAD91246}"
    Name="HeadcountRequestPositionNumber"
    SourceID="http://schemas.microsoft.com/sharepoint/v3"
    StaticName="HeadcountRequestPositionNumber"
    Group="Headcount Request Workflow"
    Type="Text"
    DisplayName="Headcount Request Position Number">
  </Field>
</Elements>

The markup in the OpsTeamTaskWFCT.xml file specifies the following about the operations team task workflow content type:

  • It inherits from the SharePoint workflow task content type by specifying 0x010801 for the base part of its content type identifier.

    <ContentType  ID="0x010801006439AECCDEAE4db2A422A3A04C79CC83"
    

    For more information on the SharePoint base content type hierarchy, see Base Content Type Hierarchy.

  • It specifies that the OpsTeamTaskWFCT.aspx file, located in the _layouts folder, provides the content type's edit form.

    <FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
      <Edit>_layouts/OpsTeamTaskWFCT.aspx</Edit>
    </FormUrls>
    
    
    
  • It references two columns, also defined in the OpsTeamTaskWFCT.xml file: one for storing comments from operations team members, and one for storing the request's position number.

       <FieldRefs>
         <FieldRef ID="{7B37146C-B563-411b-B004-9740C8E2C272}"
           Name="HeadcountRequestOpsComments"
           DisplayName="Headcount Request Ops Comments"/>
         <FieldRef ID="{10414189-35AD-40b3-AF50-740ACAD91246}" 
           Name="HeadcountRequestPositionNumber"
           DisplayName="Headcount Request Position Number"/>
    </FieldRefs>
    
    

The following table lists key Headcount Request Workflow content type files and folders.

Table 4. Key Headcount Request Workflow content type files and folders

FileDescription

LeadershipTeamTaskWFCT

Sample code folder containing the project file and source code for the Headcount Request leadership team task workflow content type.

OpsTeamTaskWFCT

Sample code folder containing the project file and source code for the Headcount Request operations team task workflow content type.

LeadershipTeamTaskWFCT.aspx

Leadership team task workflow content type edit form.

LeadershipTeamTaskWFCT.cs

Code file for the leadership team task workflow content type edit form.

OpsTeamTaskWFCT.aspx

Operations team task workflow content type edit form.

OpsTeamTaskWFCT.cs

Code file for the operations team task workflow content type edit form.

LeadershipTeamTaskWFCT.xml

XML file that contains the definition of the leadership team task workflow content type.

OpsTeamTaskWFCT.xml

XML file that contains the definition of the operations team task workflow content type.

Headcount Request Workflow Solution Deployment

The following sections provide information related to deploying the components that make up the Headcount Request Workflow solution.

Headcount Request InfoPath Form Template

Because the Headcount Request InfoPath form template uses managed code, an administrator must deploy it to InfoPath Forms Services. Deploying a browser-enabled form template that requires administrator approval for use with InfoPath Forms Services is a three-step process:

  1. Verify the form template.

  2. Upload the template.

  3. Activate the template.

To upload and activate the Headcount Request form template

  1. Navigate to the SharePoint Central Administration site, and then click the Application Management tab.

  2. On the Application Management page, click the Upload form template link in the InfoPath Forms Services section.

  3. Browse to the HeadcountRequestIPForm\Published folder under the top-level (root) Headcount Request sample folder, and then double-click the HeadcountRequisition.xsn file. This is a published version of the Headcount Request form template.

  4. Click the Upload button to upload the form template.

  5. After the form template is uploaded and its Status on the Manage Form Templates page shows Ready, pause the cursor over the template name, and then click the down arrow to display the drop-down menu. Click Activate to a Site Collection.

  6. On the Activate Form Template page, select the site collection you want, and then click OK.

For more information about deploying administrator-approved form templates, see Deploy Administrator-Approved Form Templates (Office SharePoint Server) on Microsoft TechNet.

Headcount Request Workflow

The Headcount Request Workflow with its associated forms and content types can be deployed by using one of three batch files located in the top-level folder of the Headcount Request sample. The three batch files are:

  • InstallAll.bat Installs all workflow-related assemblies to the global assembly cache; copies workflow association, initiation, and task edit forms to the SharePoint _layouts folder; and copies workflow and content type feature files to the SharePoint Features folder and installs and activates them.

  • QuickPagesUpdate.bat Copies workflow association, initiation, and task edit forms to the SharePoint _layouts folder.

  • QuickUpdate.bat Installs all workflow-related assemblies to the global assembly cache; and copies workflow association, initiation and task edit forms to the SharePoint _layouts folder.

To deploy the Headcount Request Workflow, open a Command Prompt window, navigate to the top-level folder of the Headcount Request sample, and execute the batch file you want. If you are deploying the workflow for the first time, run the InstallAll.bat file. You can use the QuickPagesUpdate.bat and QuickUpdate.bat files if the sample code is modified and the workflow features are already installed and activated.

Headcount Requests Document Library

A list template for the Headcount Requests document library is provided in the HeadcountRequestDocLibrary folder under the top-level sample folder. You can use the list template to easily create a document library that uses the Headcount Request form as its document template.

To add the Headcount Requests document library list template to the SharePoint list template gallery

  1. On the Site Actions menu, click Site Settings, and then click Modify All Site Settings.

  2. On the Site Settings page, click the List Templates link in the Galleries section.

  3. On the List Template Gallery page, click Upload to display the Upload Template: List Template Gallery page.

  4. Browse to the HeadcountRequestDocLibrary folder under the root Headcount Request sample folder, and then double-click the HeadcountRequestDocumentLibrary.stp file.

  5. Click OK on the Upload Template: List Template Gallery page to upload the template.

  6. On the List Template Gallery: HeadcountRequestDocumentLibrary page, you can modify template settings if you choose. Click OK to save the changes to the gallery.

Now that the list template is added, you can create an instance of the Headcount Requests document library.

To create an instance of the Headcount Requests document library

  1. On the Site Actions menu, click Site Settings, and then click Modify All Site Settings.

  2. On the Site Settings page, click the Site libraries and lists link in the Site Administration section.

  3. On the Site Libraries and Lists page, click the Create new content link.

  4. On the Create page, click the Headcount Request Document Library link in the Libraries section.

  5. On the New page, type a name and description for the document library, and then click the Create button.

The next step is to associate the Headcount Request workflow with the document library.

To associate the workflow with the document library

  1. Navigate to the Headcount Request document library you created previously.

  2. Click Settings, and then click Document Library Settings.

  3. On the Customize page for the document library, click the Workflow settings link in the Permissions and Management section.

  4. On the Add a Workflow page, select the Headcount Request workflow template, name the workflow, and select the workflow task and history lists. To be able to use the workflow initiation form to override the workflow settings specified at association time, leave the option to allow the workflow to be manually started.

  5. Click Next to display the Headcount Request Workflow association form.

  6. Specify the default settings for the workflow. Use the contact selector to specify the senior leadership team members to act as reviewers and the operations team members. Type messages to include with the requests, and specify the minimum number of required approvals.

  7. Click OK to save the workflow association.

The final step to create the Headcount Requests document library is to set its document template. The list template for the document library sets the document template for the Form content type to point to http://moss.litwareinc.com/FormServerTemplates/HeadcountRequisition.xsn. You must change this to point to the correct location of the Headcount Request form template.

To determine the location of the form template and set the document template to point to it

  1. On the Site Actions menu, click View All Site Content. The All Site Content page will be displayed.

  2. On the All Site Content page, click the Form Templates link in the Document Libraries section to display the list of form templates that are activated to the site collection. If the Headcount Request form was previously uploaded and activated, the HeadcountRequisition form should be listed.

  3. Right-click the HeadcountRequisition link, and then click Copy Shortcut.

  4. Navigate back to the Headcount Requests document library created previously, click Settings, and then click Document Library Settings.

  5. On the document library's Customize page, click the Form content type in the Content Types section.

  6. On the List Content Type: Form page, click , the Advanced settings link.

  7. Select the existing document template URL and replace it by pasting the form template shortcut copied in step 3.

  8. Click OK to save the change.

Now the document library is correctly configured. New headcount requests can be submitted with the Headcount Request form, and workflows can be run against forms in the document library.

Cc811589.note(en-us,office.12).gifNote:

SharePoint e-mail settings must be correctly configured to enable the Headcount Request workflow to successfully send e-mail notifications. For more information about configuring SharePoint e-mail settings, see Configure Outgoing E-Mail Settings (Office SharePoint Server).

Conclusion

The Headcount Request Approval solution presented in this article demonstrates using Visual Studio 2008 to create a SharePoint sequential workflow to facilitate a simple headcount request approval process. The solution uses an Office InfoPath 2007 browser-compatible form to allow users to submit headcount requests to a SharePoint document library. A SharePoint sequential workflow is provided, which uses ASP.NET .aspx pages for the workflow association forms and initiation forms. In addition, the workflow uses two custom content types to enable the use of custom workflow task editing forms.

Additional Resources

Community Additions

ADD
Show:
© 2015 Microsoft