Hidden columns not included in XML when adding a new row to a repeating table - InfoPath Dev
in

InfoPath Dev

Hidden columns not included in XML when adding a new row to a repeating table

Last post 10-22-2010 08:34 AM by CharlesMc. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 10-21-2010 08:04 AM

    Hidden columns not included in XML when adding a new row to a repeating table

     Hey everyone, thanks in advance for the help -

     I have a repeating table (Request) with the following columns

    <my:SFAStoreId></my:SFAStoreId>
    <my:StoreName></my:StoreName>
    <my:Address></my:Address>
    <my:City></my:City>
    <my:State></my:State>
    <my:Zip></my:Zip>
    <my:RequestType></my:RequestType>
    <my:CallFrequency xsi:nil="true"></my:CallFrequency>
    <my:EffectiveDate xsi:nil="true"></my:EffectiveDate>
    <my:Comments></my:Comments>
    <my:SM_Comments></my:SM_Comments>
    <my:hid_OrigStoreName></my:hid_OrigStoreName>
    <my:hid_OrigAddress></my:hid_OrigAddress>
    <my:hid_OrigCity></my:hid_OrigCity>
    <my:hid_OrigState></my:hid_OrigState>
    <my:hid_OrigZip></my:hid_OrigZip>
    <my:hid_OrigCallFrequency></my:hid_OrigCallFrequency>
    <my:ChangeSummary></my:ChangeSummary>

    The columns prefixed with "hid_" are hidden columns which are not bound to any control.  I use these to track the original values of the actual columns so that when changes are made, the form creates a summary of what changed (in the ChangeSummary column).

    I populate this form from a custom application by building an XML with customer records, then loading it into the form.  This works just fine. 

    The problem comes up when I use the link at the bottom of the Infopath form to create a new row.  I have code that, when certain rows change, copies the values of the visible columns to their "hidden column" counterparts (for example, StoreName copies its value to "hid_OrigStoreName", and so on).  When this code runs after I add a new row, I get an error when it hits the code to reference the hidden columns.  Upon checking the underlying XML I see that the hidden columns were not written, only some were..  I also noticed that when running the form in the Approval view, that all columns are written as expected.  In the original, "request" view, they are not (neither the hid_Orig columns nor the ChangeSummary column, which is bound to a control, but is only visible in the "Approval" view).  Obviously I need the entire row to be written to the XML file every time.  Here's code I call to set / compare one of the current values to their "original (hidden)" value counterparts.  I have similar code on the Changed events of the other fields.  This is the first code that fires when I add the new row (the other columns' Changed events fire immediately thereafter), and by this time the new line has already been written to the underlying XML:

             public void CallFrequency_Changed(object sender, XmlEventArgs e)
            {
                //Get the full row of the changed column and check for deviations
                //from original values
                XPathNavigator xNav = e.Site;
                xNav.MoveToParent();
                ProcessColumnValues(xNav);
            }

    ProcessColumns is the procedure that takes the new (parent) row and compares all the values.  Here's a code segment that has the problem in that procedure (there are similar blocks in this procedure for handling the other columns in the row, but this is the first one):

            private const string LOCAL_REQUEST_PREFIX = "my:";
            private const string HIDDEN_REQUEST_PREFIX = "hid_Orig";

                    string propString = LOCAL_REQUEST_PREFIX + "StoreName";
                    string origPropString = string.Format("{0}{1}{2}", LOCAL_REQUEST_PREFIX,HIDDEN_REQUEST_PREFIX, "StoreName");

                    //Saves original control value on first population
                    if (xNav.SelectSingleNode(origPropString,this.NamespaceManager).Value ==string.Empty)
                        {
                            //save original value
                            //CreateNavigator().SelectSingleNode(origPropString, NamespaceManager).SetValue(CreateNavigator().SelectSingleNode(propString, NamespaceManager).Value);
                            xNav.SelectSingleNode(origPropString, NamespaceManager).SetValue(xNav.SelectSingleNode(propString, NamespaceManager).Value);
                        }

     Upon checking the XML file itself (via Save As), I get this for the new row:

              <my:SFAStoreId xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-17T17:25:26"></my:SFAStoreId>
              <my:StoreName xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-17T17:25:26"></my:StoreName>
              <my:Address xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-17T17:25:26"></my:Address>
              <my:City xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-17T17:25:26"></my:City>
              <my:State xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-17T17:25:26"></my:State>
              <my:Zip xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-17T17:25:26"></my:Zip>
              <my:RequestType xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-17T17:25:26"></my:RequestType>
              <my:CallFrequency xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-17T17:25:26" xsi:nil="true"></my:CallFrequency>
              <my:EffectiveDate xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-17T17:25:26" xsi:nil="true"></my:EffectiveDate>
              <my:Comments xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-17T17:25:26"></my:Comments>
              <my:SM_Comments xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-17T17:25:26"></my:SM_Comments>

    As you can see, none of the hidden columns are there (neither is ChangeSummary which is bound to a control, but is only visible on the "Approval" view), which is why it fails the first time it tries to reference one of them.  I've tried adding code to test for the existence of, and create if necessary, the hidden column(s) in question-  but I can't find any code that will do that either (I can find code to see if the node exists, but for creating a new column at run-time in InfoPath; I've had no luck).  Of course, I'd prefer to have the entire column set created in the schema as expected when the user clicks "Add a new Request" at the bottom.

    I've also looked in the manifest,xsf and did find the schema defined once in each view (the "request" and the "approval" views), and only the visible columns were defined for the schema in the "request" view.  Of course I thought I had found the problem, but when I pasted the hidden columns over from the "approval" view XML to the "request" view, there was no change in the behavior when adding the row.  I tried rebuilding, even restarting InfoPath thinking I needed to refresh something because of the manual change to manifest.xml, but no dice.

    It just seems like something is out of sync in the code somewhere, that whatever process that is adding the row is not using the correct version of the schema or (most likely) I am overthinking this and there is a simple explanation that someone with more InfoPath experience than I can find very quickly.  I can find no event that fires when adding a new row, nor can I find another place where maybe this code was added elsewhere, so I'm pretty stuck at this point.  I did pick this up from another developer who is no longer with the company, or I'd ask him :)  I've been developing with Microsoft and .NET technologies for 15+ years, but Infopath (and even XML) is still pretty new to me.

    Folks, any help would be greatly appreciated!  Is there anything that comes to mind?  Thanks much -

     Charles

  • 10-22-2010 08:34 AM In reply to

    Re: Hidden columns not included in XML when adding a new row to a repeating table

    So I discovered the issue myself... on the design view, under repeating table properties (that tiny little link underneath the repeating table!), under "Edit Default Values"; the original developer had selected the individual rows to include when inserting a row (under "Select the fields and groups to include when the user inserts a row in the table").  I checked the new (hidden) rows i created and all was right with the world..

     That button down there for "repeating table" was pretty small, so it was not immediately obvious at first glance.  Hopefully this will help someone else down the road..!

     Charles

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