Friday, June 24, 2011

Upgrade existing InfoPath 2007 form (including data) to new InfoPath form version

My problem:
My client currently had an InfoPath form published to a forms library in SharePoint. They wanted some amendments made to the form, including additional fields.
They wanted all the existing forms within the library to have all the new version's amendments.
This was not going to be possible with a normal InfoPath form upgrade.


My solution:

What I did was:
  1. Extracted the data from the old form and temporarily stored it.
  2. Created a new form with the same name and overwrote the existing form.
  3. Populated the new form with the stored data.
All this was done using 2 workflows. (I am currently using Nintex Workflows).


First workflow
  • Using workflow actions:
    • I query the list for all items matching the content type version 1 of the InfoPath form.
    • I loop through the results of this query:
      • using a 'Query XML' action, I retrieve the data from the existing form.
      • I create a new item using the 'Create an item' action. I set the name to exactly the same name as the current form item and specify 'Overwrite an existing item'. I store all data retrieved in the 'Query XML' in a temporary field value which I called 'Form XML'. When the new item is created it overwrites the current item preserving it's ID.
      • I then kick off a second workflow using the Nintex web service method called StartWorkflowOnListItem. (http://<site>/_vti_bin/nintexworkflow/workflow.asmx). This workflow kicks off on a specific item specified by the list item ID.
Second Workflow
  • Using multiple 'Query XML' actions I retrieve the data from the temperary field I stored it in.
  • Using an 'Update XML' I update the new form with the old data.
That sounds simple enough :)
I have excluded any business rules I have in my current workflows for the purposes of this blog.

Some of you might be wondering why I used a temperary field to store the data instead of passing the data via the web service method using the associationData tag.
I had issues when passing the data using the a associationData tag. The temperary field was a quick and easy workaround I could implement as this solution was going to be used as a once off to upgrade existing forms.

      No comments:

      Post a Comment