Friday, August 27, 2010

InfoPath form and Workflow in SharePoint 2010 – Putting pieces together

To set up a InfoPath form as the instantiation form in a workflow in SharePoint 2010 is not that easy and it requires some manual setting here and there. What making it harder is the lack of documentation. Following is the details of the whole process:

 

Create and Publish a InfoPath form in InfoPath Designer 2010

There are tons of posts online walk you thru creating a workflow init InfoPath forms. After you created one, now there is a few steps you need to know about when it comes to publish.

First, you’ll need to set the security level of the form. It’s under File/Info/Advanced form options/Security and Trust. Set it to Domain.

Second, set the server validation under File/Info/Advanced form options/Compatibility.

Last, publish it to a Network Location which is a folder on your local machine. When it comes to the step that asks you for an alternate access path, leave it blank then click next. If you don’t leave it blank, you will get an error of can not access the form on the server.

image

You will also need to get the URN of the form for later use: it’s under File/Info/Form Template Properties (on the very right hand side)

image

 

Add and Set up the forms published above in Visual Studio

First, add the forms. To add the forms, the convenient way is to add a new Module item in the project, then add the forms under. The feature will automatically include this new added Module and all the files under it.

Notice that the path property of the forms is set to blank. It’s because we are going to use Microsoft.Office.InfoPath.Server.Administration.XsnFeatureReceiver as the feature event receiver which looks for InfoPath forms in the top level folder only.

Set the Forms Module feature receiver assembly to “Microsoft.Office.InfoPath.Server, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”.

Set the Class Name to “Microsoft.Office.InfoPath.Server.Administration.XsnFeatureReceiver”.

image

 

Second, modify the Elements.xml under the Forms Module according to the following:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="Forms" Url="FormServerTemplates" RootWebOnly="TRUE">
<File Path="InitiationForm.xsn" Url="InitiationForm.xsn" Type="GhostableInLibrary" />
<File Path="TaskForm.xsn" Url="TaskForm.xsn" Type="GhostableInLibrary" />
</Module>
</Elements>

 

Third, modify the Elements.xml under the workflow folder which is CollectResponse in this example (use the form’s URN copied from above):

<?xml version="1.0" encoding="utf-8" ?>
 
<!-- Customize the text in square brackets. 
Remove brackets when filling in, e.g.
Name="[NAME]" ==> Name="MyWorkflow" -->
 
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Workflow
     Name="CollectResponseWorkflow - CollectResponse"
     Description="My SharePoint Workflow"
     Id="9bfcf279-c26d-48c1-91c6-6477bf3369ef"
     CodeBesideClass="WorkflowProject2.Workflow1.Workflow1" 
     InstantiationUrl="_layouts/IniWrkflIP.aspx" 
     ModificationUrl="_layouts/ModWrkflIP.aspx"
     CodeBesideAssembly="$assemblyname$">
    <Categories/>
    <MetaData>
      <AssociationCategories>List</AssociationCategories>
      <!-- Tags to specify InfoPath forms for the workflow; delete tags for forms that you do not have -->
      <!--<Association_FormURN>[c FOR ASSOCIATION FORM]</Association_FormURN>-->
      <Instantiation_FormURN>urn:schemas-microsoft-com:office:infopath:InitiationForm:-myXSD-2010-08-25T19-12-01</Instantiation_FormURN>
      <Task0_FormURN>urn:schemas-microsoft-com:office:infopath:TaskForm:-myXSD-2010-08-25T19-44-10</Task0_FormURN>
      <!-- Modification forms: create a unique guid for each modification form -->
      <!--<Modification_[UNIQUE GUID]_FormURN>[URN FOR MODIFICATION FORM]</Modification_[UNIQUE GUID]_FormURN>
      <Modification_[UNIQUE GUID]_Name>[NAME OF MODIFICATION TO BE DISPLAYED AS A LINK ON WORKFLOW STATUS PAGE</Modification_[UNIQUE GUID]_Name>
      -->
      <StatusPageUrl>_layouts/WrkStat.aspx</StatusPageUrl>
    </MetaData>
  </Workflow>
</Elements>

 

Last, modify the Feature1.Template.xml as shown in the following:

<Feature xmlns="http://schemas.microsoft.com/sharepoint/" Description="SharePoint Workflow Feature"
         Id="1f2088c0-3921-44ad-aa63-a531034b087f"
         ReceiverAssembly="Microsoft.Office.InfoPath.Server, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" 
         ReceiverClass="Microsoft.Office.InfoPath.Server.Administration.XsnFeatureReceiver" 
         Scope="Site" Title="CollectResponseWorkflow">
  <Properties>
    <Property Key="GloballyAvailable" Value="true" />
  </Properties>
  <ElementManifests>
    <ElementManifest Location="CollectResponse\Elements.xml" />
    <ElementManifest Location="Forms\Elements.xml" />
    <ElementFile Location="InitiationForm.xsn" />
    <ElementFile Location="TaskForm.xsn" />
  </ElementManifests>
</Feature>

 

Deploy your project and check the Form Templates in Central Admin

The two forms in this example are published with Workflow Enabled.

image

 

Tips

You might not be able to start a workflow after a second publish and need to manually enable it (there should be a way to avoid this).

Click Remove a workflow in the following screen

image

Click Allow

image

No comments: