Showing default values from Secondary Data Sources - David Airapetyan
in

InfoPath Dev

David Airapetyan

Showing default values from Secondary Data Sources

 Unlike the main data source, secondary data sources have an annoying property of not displaying the values stored in the XML when the view controls are bound to them. It turns out that it does not have to be this way – a small hack can fix it.

Consider the following XML file (called data.xml):

<?xml version="1.0" encoding="utf-8"?>

<root>

      <data>My Data</data>

</root>

Let’s import it into InfoPath and bind a textbox to the "data" field:

1.       Design a blank form (I am using InfoPath 2007 but this should work with 2003 as well)

2.       Add an XML data connection, pick data.xml as the file, accept all the defaults

3.       In the data source pane, switch to the "data" source and drag the data field into the view

As a result, the text "My Data" does not show

4.       Save as source files

5.       Close the Designer

6.       Open sampledata.xml which would look similar to that:


<my:myFields ..>

      <xd:SchemaInfo ...>

            <xd:Namespaces>

                  <xd:Namespace .../>

            </xd:Namespaces>

      </xd:SchemaInfo>

      <xd:DataConnection Name="data">

            <root ...>

                  <data/>

                  <xd:SchemaInfo LocalName="root" NamespaceURI="">

                        <xd:Namespaces>

                              <xd:Namespace .../>

                        </xd:Namespaces>

                  </xd:SchemaInfo>

            </root>

      </xd:DataConnection>

</my:myFields>

7.       As you can see, it contains the copy of your secondary data source but the data is not there. Now simple replace the <data/> node with the value from your XML file, namely <data>My Data</data>.

 

 

8.       Save  sampledata.xml, open the solution in the Designer

 

Result: now the value shows in the Designer!

 

Warning: sampledata.xml is an internal InfoPath Designer file. Modify it at your own risk. Although I have tested the steps above and they seem to work in both InfoPath 2003 and InfoPath 2007, there is no guarantee your values will be preserved. The functionality may also change in future versions of the product.

Comments

No Comments

About davidair

I am a Computer Science graduate from McGill University in Montreal, Canada. I have over seven years of industry experience including almost five of them spent with the Microsoft Corporation where I shipped several versions of Microsoft Office InfoPath. Originally from Russia, I am fluent in several languages, including Russian, English, French, C#, C++ and Perl. I currently reside in Montreal and work for Qdabra Software.
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.