Problem with Form Version Upgrade code C# - InfoPath Dev
in

InfoPath Dev

Problem with Form Version Upgrade code C#

Last post 05-31-2012 01:53 PM by boreal. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 05-24-2012 10:15 AM

    • boreal
    • Not Ranked
    • Joined on 05-24-2012
    • Posts 3

    Problem with Form Version Upgrade code C#

    I'm working to upgrade a browser based InfoPath 2010 form in a SharePoint library with tonnes of filled out copies of the form.

    The form design needs to change rather drastically and I need to handle the case where an old version of the form opens, is upgraded, and legacy data is lost due to changes in the schema from the upgrade.

    I have done a fair bit of research and think that the best option would be to use the FormEvents_VersionUpgrade function to copy values from legacy nodes to new nodes on version upgrade (to avoid data loss). However, I quickly ran into a problem with my code just trying to do a test SetValue to one of my new nodes (AllReq).

    Receiving an error 5337 "Object reference not set to an instance of an object".

    Here's my code:

            public void FormEvents_VersionUpgrade(object sender, VersionUpgradeEventArgs e)
            {
                XPathNavigator xMain = MainDataSource.CreateNavigator();
                XPathNavigator AllReqPath;

                AllReqPath = xMain.SelectSingleNode("//my:AllReq", NamespaceManager);

                if (AllReqPath.Value == null)
                {
                    AllReqPath.SetValue("xxxxxxxx");
                }
            }

    Any assistance would be greatly appreciated!

    ps is there a way to handle version upgrade with Qrules?

     Phil

  • 05-24-2012 11:32 PM In reply to

    Re: Problem with Form Version Upgrade code C#

    A NullReferenceException here will almost always mean that the node you are trying to select was not found.  Is my:AllReq a field from before or from after the modifications?

     We have tentatively looked into adding custom version upgrade feature to qRules, but unfortunately haven't come up with a good way to do it so far.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 05-25-2012 02:30 PM In reply to

    • boreal
    • Not Ranked
    • Joined on 05-24-2012
    • Posts 3

    Re: Problem with Form Version Upgrade code C#

    Thanks for the quick response, Jimmy.

    Ah, my:AllReq is the new field and the form's schema update hasn't happened yet when VersionUpgrade is called, right? So that node is not found.

    Hmm, where should I copy the legacy node data to then?

    Am I way off base here? Sorry for my noobness.

  • 05-26-2012 08:37 AM In reply to

    Re: Problem with Form Version Upgrade code C#

    If you use the custom upgrade with code option, that means the burden is on you to write code to determine what needs to be upgraded and make the modifications therein.  The automatic upgrade functionality gets turned off.  That's a pretty big hassle and a reason why it's usually not a good idea to do the upgrade in code or change the main data source in such a way that would break the automatic upgrade.  How drastically did you change it?

    What are you using to store your documents?  SharePoint?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 05-31-2012 01:53 PM In reply to

    • boreal
    • Not Ranked
    • Joined on 05-24-2012
    • Posts 3

    Re: Problem with Form Version Upgrade code C#

    Thanks again, Jimmy. I will take a different approach that means more grunt work and less coding. <lame, i know>

    I will create a new field and write a FormEvents_Loading function that will copy the contents of my old fields to my new field. Open/save each form in turn to concatenate the old data and paste it into the new field. Then, I will remove the old fields and re-design the form, as required.

    Yup, these docs are being saved in SharePoint.

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