Monday, July 6, 2009

Infopath Form Migration hints

Last week, my manager had me open a ticket with Microsoft to talk about Infopath form migration.  We've been finding that it is time-consuming to migrate a form designed on the test server to the staging or production servers.   

Microsoft had some very good recommendations.  I've taken what they suggested and applied it to a purchase requisition form I'm working on.  It used to take me about 30 minutes to migrate my form to a new server.  Now all it takes is a 1 minute re-publish.  No other changes are necessary. 

Data Sources

With the exception of the Submit data source, I'm trying not to use these anymore on my own forms.  Their major draw-back, in my opinion, is that you cannot tell what fields are using a Data Source without opening the Field Properties.  When you have a few hundred fields, this quickly becomes annoying.  

Begin by creating your Data Source as normal.  Once it has been created, open Tools…Data Sources.

Select the Data Source and click the Convert button. 

In the Window that pops up, you want to keep the Connection link type set to "Relative to Site Collection"

Type in the following URL for the location http://Server/DataConn/XXXXX, where Server is the address of your Sharepoint Server, and DataConn is a Data Connection Library on that server.

Make sure that XXXXX is unique for your form and your data source. 

That "Relative to site collection option" means that your form will look for a Library called DataConn in the root of whatever site it finds itself on.  This is what lets us move our forms from server to server.   

Click OK and your Data Source will be converted into a file and uploaded to the DataConn library. 

The DataConn library requires that new documents are Approved before they can be referenced.  Browse to the Library, find your new document and use the context menu to approve it.

We now need to copy our new Data Source file to other servers where we want to use our form. 

Begin by downloading a copy of the file.  Before we upload the file to the new server, we need to modify it so that the Data Source is pointed to the new server.  Luckily, the Data Source is just an XML file.  Open it using Notepad or any other Text Editor. 

You'll find that the references to the server are easy to find.  I've high-lighted them below.  Just change the references to the correct server path and save your changes. 

 

<?xml version="1.0" encoding="UTF-8"?>

<?MicrosoftWindowsSharePointServices ContentTypeID="0x010100B4CBD48E029A4ad8B62CB0E41868F2B0"?>

<udc:DataSource MajorVersion="2" MinorVersion="0" xmlns:udc="http://schemas.microsoft.com/office/infopath/2006/udc">

                <udc:Name>Main submit</udc:Name>

                <udc:Description>Format: UDC V2; Connection Type: SharePointLibrary; Purpose: WriteOnly; Generated by Microsoft Office InfoPath 2007 on 2009-07-06 at 15:03:35 by CORP\kenna.</udc:Description>

                <udc:Type MajorVersion="2" MinorVersion="0" Type="SharePointLibrary">

                                <udc:SubType MajorVersion="0" MinorVersion="0" Type=""/>

                </udc:Type>

                <udc:ConnectionInfo Purpose="WriteOnly" AltDataSource="">

                                <udc:WsdlUrl/>

                                <udc:SelectCommand>

                                                <udc:ListId/>

                                                <udc:WebUrl/>

                                                <udc:ConnectionString/>

                                                <udc:ServiceUrl UseFormsServiceProxy="false"/>

                                                <udc:SoapAction/>

                                                <udc:Query/>

                                </udc:SelectCommand>

                                <udc:UpdateCommand>

                                                <udc:ServiceUrl UseFormsServiceProxy="false"/>

                                                <udc:SoapAction/>

                                                <udc:Submit/>

                                                <udc:FileName>Specify a filename or formula</udc:FileName>

                                                <udc:FolderName AllowOverwrite="0">http://serverAddress/LibraryName</udc:FolderName>

                                </udc:UpdateCommand>

                                <!--udc:Authentication><udc:SSO AppId='' CredentialType='' /></udc:Authentication-->

                </udc:ConnectionInfo>

</udc:DataSource>

This example is for a Submit Data Source.  Other Data Sources will look slightly different, and may have more than one field that needs updating.  If you're pulling data from a List, you may need to know the List GUID.   

Now that you have your Data Source file updated, you just need to upload it the DataConn library on the new server and Approve it. Repeat for each server that you need to use your form on. 

Web References in Code-Behind

Next up were Web References being used with code-behind in our forms.  It turns out that these references can be easily fixed with a single additional line of code.   

Begin by creating your Web Reference as usual.  Once created, take a look at the Web Reference properties.  You'll see the URL being referenced.  This is what we'll need to update on the new server.

In the case of my Purchase Req form, I'm calling the UserGroup web service that comes standard with Sharepoint.  The URL that is referenced,  /_vti_bin/usergroup.asmx, will exist on any Sharepoint server. 

//Open current Site

using (SPSite mySite = SPContext.Current.Site){

//Create Web Reference

GetGroupMembers.UserGroup getUsersFromGroup = new GetGroupMembers.UserGroup();

//Redirect URL

getUsersFromGroup.Url = mySite.Url.ToString() + "/_vti_bin/usergroup.asmx";}

1 comment:

Simon said...

Very neat solution. Thanks for posting this. We've been struggling with this problem as well.