Friday 17 December 2010

Deploying InfoPath forms to SharePoint production environment


In one of my recent projects I had an interesting problem moving InfoPath 2007 form from my development environment to the production. Actually browser compatible InfoPath form was a part of the system implemented with SharePoint 2007.

Deploying InfoPath forms should not be a big deal, besides Microsoft provides quite detailed guidelines for deploying InfoPath 2007 Form Templates (http://msdn.microsoft.com/en-us/library/cc704269(v=office.12).aspx).   Approach described in that article works fine but it requires InfoPath designer installed in production environment. In my case InfoPath designer was not available in the production. Things are getting even trickier when InfoPath form is not a simple one but it has data connections to external sources, “code-behind” plus it should be browser-compatible. 

So here is the approach that I found out to meet requirements to the production environment when deploying browser-enabled InfoPath template with external connections and “code-behind” to production SharePoint server:
  • Obviously all data connections should be converted into a Universal Data Connection (UDC) files. A UDC file stores data connection settings and resides in a SharePoint Server data connection library (DCL). So initially I created those data connections in local data connection library (library in my site collection, in which InfoPath form was used). Then links to DCL in InfoPath form were converted into centrally managed connection library


  • In my development environment I published InfoPath form template for uploading to SharePoint server (URL to my development SharePoint server) and stored it to “a network location”


  • Then I copied deployment package that included published InfoPath template and all UDC files to production server and uploaded form template to production SharePoint server with SharePoint Central Administration application. UDC files should also be uploaded to centrally managed connection library (obviously you need to setup parameters of connections to production resources before uploading those files)
  • Now you can activate uploaded InfoPath template to your site collection and finalize all needed settings to use form template in your application. From this point the form should be working as in your development environment
Some more complexity to those forms was brought by promoted properties. Some of fields in InfoPath form were “promoted” to SharePoint library and accessible in application as library columns.


Basically, the process of deploying InfoPath form with promoted properties is exactly the same as described above. Additionally, fields to be promoted should be mapped to relevant site columns (this can be set in Form Options \ Property Promotion). To guarantee that SharePoint library in production possesses needed columns, relevant site columns were created as a part of deployment script and associated with forms library. When InfoPath form is being uploaded to the server and activated to a site collection it just links to the previously installed site columns by their names.

Wednesday 24 November 2010

Displaying dependent data from external data sources in repeating tables in InfoPath forms


Introduction


Displaying dependent information from external data sources is a very common requirement for InfoPath forms in SharePoint projects. Some scenarios can be easily covered with out-of-the-box means; others are trickier especially in web compatible forms. Below is a description of simple solution for displaying related information from external data sources in repeating tables.

Problem Description

This requirement occurred in one of real projects related to building time registering system based on SharePoint with extensive use of InfoPath forms for implementation of timesheets. There were lots of requirements to those timesheets like different versions for different departments, calendars with bank holidays, extra security for sensitive data and so on. 


One of the requirements was to display descriptions for specific absence reasons.  Here is a brief description of the problem and fragment of structural model. 


This is a fragment of structural model for the timesheet (this is just logical entity model with no implementation details yet). Timesheet contains a list of Absences. Each Absence has a reference to Absence Reason, which has a title and description.

Timesheet is implemented as InfoPath form. The requirement is to maintain a table of absence reasons selecting absence reason from drop-down with all absence reasons available in the system. When an absence reason is selected for record, comments corresponding to the selected reason should appear in another column in this table. 


All absence reasons available in the system are maintained in a SharePoint list.



Problem Solution

InfoPath form for Timesheet contains a repeating table for daily records where one of the properties is Absence Reason.
Absence Reasons lookup is added to the form as Data Connection to external source to the SharePoint list containing all values for absence reasons in the system.

Then in properties for field corresponding to Absence Reason in main data source (W1AbsenceReason) set default value as shown in figure below:

XPath expression for this value looks like this:
xdXDocument:GetDOM("Absense Reasons")/dfs:myFields/dfs:dataFields/dfs:Absense_Reasons/@Description[../@Code = current()/../my:W1AbsenseReason]

Limitations

This approach is compatible with Web forms, which makes it useful in wide range of applications. But be very careful with this approach on Web; when the form is rendered as a Web page and delivered to the browser, all data from external data source is loaded to the client, which can make the page too heavy if the number of records in referenced external data source is big enough.