Applying New InfoPath Template Columns to Existing Forms in SharePoint Document Library - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Applying New InfoPath Template Columns to Existing Forms in SharePoint Document Library

Last post 05-13-2019 03:33 PM by Hilary Stoupa. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 05-13-2019 07:46 AM

    Applying New InfoPath Template Columns to Existing Forms in SharePoint Document Library

    I have a question about updating InfoPath form templates in a SharePoint document library. The library has ~70,000 records (InfoPath forms). I updated the form template to include some additional columns and would like to apply this change to the previous records. Specifically, I would like the InfoPath XML files to contain the (empty) columns.

    From testing, I see that publishing the form template, opening an older form, and either saving or submitting it will propagate the new columns to the XML. However, this is not practical for 70k records. I tried re-linking the forms, using C# CSOM to check-out/check-in all the documents, and using C# to save all the documents - none of these approaches worked. My understanding is that these didn't work because the form was never 'opened' in InfoPath (either in the browser or application), and so even though the form template was linked, it was never applied.

    Is there a way to both link and apply a new InfoPath template to existing forms? The only option I can think is to write a script that opens each file in the InfoPath application and save/submits it to the existing library. However, I am unsure of how to do this or if it is even possible. The other option is to write a script which adds new XML fields to the existing documents, but would that not conflict with the new template? If anyone has any advice, it would be greatly appreciated.
  • 05-13-2019 08:24 AM In reply to

    Re: Applying New InfoPath Template Columns to Existing Forms in SharePoint Document Library

    I would add the new fields to the XML without trying to open each one in InfoPath, just directly updating the XML file - and I'd probably do that via applying an XSLT. If you save your form template as source files (from the Publish menu) you'll find upgrade.xsl in those files. That is what InfoPath is applying to your existing XML when you open them. Test with a small sample, make sure you have made a backup of your test files first - but applying the upgrade.xsl should have the same result as opening / submitting each file.
    Hilary Stoupa

  • 05-13-2019 01:34 PM In reply to

    Re: Applying New InfoPath Template Columns to Existing Forms in SharePoint Document Library

    Hi Hilary,

    Thank you for your suggestion and explanation. I've tested using your suggestion and so far it has worked well. As a general note, if anyone is looking to do this in Python, I've shared my code below. The general structure is to loop through an InfoPath file directory, apply the update, and write the XML to a new file in a secondary location.
    ------------------------------------------

    import lxml.etree as ET
    import os

    directory = 'W:' #Mapped SharePoint directory to network drive
    newdirectory = 'C:\\newXML' #Location to write new InfoPath XML files to

    xslpath = 'C:\\SPFiles\\upgrade.xsl' #Location of 'upgrade.xsl' file

    for filename in os.listdir(directory):
    filepath = directory + '\\' + filename
    newpath = newdirectory + '\\' + filename

    dom = ET.parse(filepath)
    xslt = ET.parse(xslpath)

    transform = ET.XSLT(xslt)
    newdom = transform(dom)
    newxml = ET.tostring(newdom, pretty_print=True)

    f = open(newpath, 'wb')
    f.write(newxml)
    f.close()
  • 05-13-2019 03:33 PM In reply to

    Re: Applying New InfoPath Template Columns to Existing Forms in SharePoint Document Library

    Thank you so much for sharing your code sample - I am sure others will find it useful.
    Hilary Stoupa

Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.