Freigeben über


Relinking forms and form templates

We often see issues when people move forms and templates from one location to another. In fact, the linked nature of InfoPath forms and templates is probably one of the hardest aspects of InfoPath to understand. While the complexities can sometimes seem burdensome, the truth is that the overall model is actually quite simple. Once understood, all it takes is a few small tricks and you will find that moving forms and templates isn’t really that difficult. Moveover, you will have a much better understanding of how InfoPath works.

The Basics

InfoPath works by associating a form instance with a form template. The way we do this is typically through a URL association. When you design a form template, it stores the entire description of how the form functions. When published, the form template is put in a location we refer to as the publishUrl (though we expose this in the publish wizard as the access path). Regardless of the name, the key point is that the form template resides in a well known location. 

Once published, the form template can be used to create new form instances, or just forms. When you create a form against InfoPath, we save the data as straight XML and associate this XML with the form template via a URL. With the URL we know how to associate the form design (layout, business logic, validation, code, etc) with the form.

The Diagnosis

As you would expect, things get wonky when the association fails to resolve correctly. This typically manifests itself in one of two ways:
1) A form won’t seem to update itself when you publish a new version
2) A form just plain won’t open

You can usually tell pretty quickly if this is really the issue by creating a new form from the published form template and comparing the processing instructions (PI’s) between the old forms and the newly created form. What you are looking for is this (I have omitted some content for clarity):

<?mso-infoPathSolution solutionVersion="1.0.0.200" productVersion="12.0.0" PIVersion="1.0.0.0" href="http://server/site/template.xsn"?>

If the two form files don’t have the same href attribute in the PI, then you have yourself a linking issue.

The Remedy

Once diagnosed, the problem is actually quite easy to fix and can be done in one of several ways. Let’s take a look…

Hand Edit: The most obvious solution is to simply change the href attribute in the PI to point to the correct form template. You can do this by opening the XML file in your favorite text editor and just correcting the href attribute to point to the correct location. This works great for one or two files but is tedious and mind numbing if you have more than a handful.

Re-Link: If your form template is in a Windows SharePoint Server form library, then you can use the built in re-link feature to manage the re-linking for you.  Simply move the forms from the old location to the new form library. Once there, you can force a re-link operation. In WSS v2, you can do this by opening the form library, selecting Modify settings and columns, and clicking on the Relink forms to this form library link. In WSS v3, you can access the re-link functionality by selecting the Relink Documents view from the View dropdown. When you perform the re-link, WSS will scan all the XML files for the href in the PI and if it doesn’t match the location for the template associated with the form library, the PI will be updated. 

PIFix: Finally, if your forms and your form template are living on a file share somewhere, then you can use the PI Fixup tool (pifix.exe) provided in the InfoPath 2003 SDK. This tool will allow you to process any number of input files and change attributes in the form to match your target form template.  Follow the instructions in the SDK or the tool to re-link your form files.

Caveats

As with any “under the hood” job, there are caveats.  You will want to make sure you understand what you are doing so you don’t wind up with “extra parts,” as it were.  When changing forms to work against different templates, there are two major things you want to think about before you re-link:
1) Schema changes
2) Versioning

Schema changes are perhaps the most serious issue because they can create data loss if you aren’t careful. By default, InfoPath enforces schema when opening forms against templates.  If the forms XML doesn’t match the schema, we don’t load it. By default, InfoPath works to address this by performing version upgrades on the XML when it doesn’t match the schema. This is great because you don’t need to worry that existing forms will break when you make changes to the form template. However, keep in mind that when elements and attributes don’t match the form template schema, existing data may be deleted to make the form schema compatible. Here is what happens:
- Add elements/attributes: No worries. If you add elements or attributes to the form template, InfoPath silently adds the element or attribute to the form XML.
- Delete elements/attributes: Think about it... You deleted the elements and attributes from the form template, so we will remove them from the XML file too. Chances are you didn’t need it anyway (why delete it otherwise?), but you want to pay attention here.
- Move elements/attributes: Really think about it... When you move an item in the form template’s data source, we treat that as a delete and then an add.  So be aware that data might disappear!
The bottom line, make sure you understand the schema implications of linking your form to a potentially different form template.

Versioning issues can cause minor headaches but don’t impact the ability of the form to open nor contribute to possible data loss. The key here is to make sure the solution version attribute in the form’s PI is less than that of the published template. You can find the version number of your form template in the form options dialog as seen below:

If the form’s version is higher than that of the form template, the you will simply receive a warning message when opening the form telling you that you are opening it against an older template.

Happy re-linking!!!

Nathaniel Stott
Program Manager

Comments

  • Anonymous
    June 26, 2007
    What's the best/recommended way to programmatically relink all the forms in WSS 3.0? I have 7 form libraries with thousands of forms in each. Using the built in relink feature will still be tedious and time consuming. Can I use PIFix directly against form library if it's a web folder? Thanks.

  • Anonymous
    May 31, 2011
    We have a tool which might be of assistance. See: www.codistri.com/relink-infopath-forms Download the User Guide for more information on how this tool can painlessly relink thousands of Infopath forms.

  • Anonymous
    March 29, 2012
    This is really a great post a useful one..Thank you so much for taking time to share your great experience here with us..<a href="www.webdesignbizz.com/">Template Design</a>

  • Anonymous
    September 14, 2012
    Thank a lot... This is the kind of post you can read without getting asleep.. really usefull

  • Anonymous
    April 16, 2013
    When relinking all documnets in a form library the template URL is calculated to: http://root/FormServerTemplates/form.xsn However the form is actually located at: http://root/sites/site/FormServerTemplates/form.xsn How does SharePoint determint the Template liink path? How do I ensure the proper path is used? Thank you for your assistance.

  • Anonymous
    May 26, 2014
    Yeah, I edit the version number and the form instance still uses an older template. What gives?