Mapping Data from Nested Repeating Tables to a SQL Database - DBXL v2.2 - Hilary Stoupa
in

InfoPath Dev

Hilary Stoupa

Mapping Data from Nested Repeating Tables to a SQL Database - DBXL v2.2

Sometimes it seems that InfoPath form templates are like snowflakes -- no two are alike. I thought it might be helpful to have more samples of data mapping using DBXL, and figured I may as well try DBXL v2.2 (available for download on Qdabra.com). It's new -- I'm new -- we have a lot in common. I'm also using InfoPath 2007 and SQL Express 2005.

For this sample, I've created a Status Report form (you can download a copy by right-clicking here and selecting "Save Target As..."). It has a repeating section for projects, with a nested repeating section for any issues. The main data source looks like this:
Main Data Source

The template has a straightforward design -- a repeating table bound to Project and an optional section bound to Issues with another repeating table bound to Issue.

In design mode, the template looks like this:
Design Mode

And in preview:
Preview Mode

A couple of points -- my form is configured to submit to my DBXL webservice -- the sample available for download above is now. Also, we need to set up a database for the data we'll be mapping from our form. We want to be sure to use compatible data types when we do that. My form has several date fields that I'll want to map to datetime SQL columns. We also want to make sure that our columns are the correct size for the data we wish to insert. I asked David Airapetyan for some guidance on database design for mapping the other day and he said:

As a rule of thumb, you want the data field size to be the maximum of what you expect the user to enter. For example, a phone number will unlikely be more than 30-40 characters even with spaces, country codes and extensions.

The task of picking the data field size is not trivial. For example, some people have very long names that can break your expectations. When you set up DBXL shredding and the actual field size is greater to what you have specified in the database, a shredding error will occur. One best practice to avoid those issues is to set the maximum textbox length in InfoPath to match your column size in the database.

So, when you create your database column size, if your fields in your form do not have limits, you may want to set them. If you can't change your form, you may want increase your column size.

Because of my two repeating groups, I plan to create two tables. I'm naming my datbase StatusReports and my tables Projects and Issues. My Projects table looks like this:
Projects table design

And my Issues table:
Issues table design

I have given my table columns the same names as my form fields. That is not required, but I lack imagination. Note that I added an ID column (ReportId) to my table that isn't related to a field in my form. I set ReportId as my primary key in my Projects table -- I also set it as an identity so that it would auto-increment:
Identity for Projects table

Finally, I created a foreign key relationship between my Issues table and my Projects table on ReportId. While not necessary for the form to shred correctly, it is always a good idea to make those table relationships formal.
Foreign key relationship creation

Now that my database is set up, I'll publish my form and attach it to the DBXL Administration Tool for my DBXL installation (DAT).

 First, open DAT, and select New Configuration:
New Configuration button

Then name your configuration and attach your published form:
DAT General Tab

Select the Database tab:
DAT Database Tab

We need to fill in the Connection String field. The connection string, if you wish to use integrated authentication, is written thus: Integrated Security=SSPI;Data Source=<server>;Initial Catalog=<database>  with <server> and <database> replaced with the name of your server and your database. For SQL Authentication, the connection string would be: Data Source=<server>;Initial Catalog=<database>;User Id=<userId>;Password=<password> with, of course, <userId> and <password> replaced with your information.

You'll see a Test Connection button after you tab out of the Connection String field -- be sure to give it a click:
Test Connection Button

A message box will pop up and tell you if your connection was successful. If it fails, the reason for failure will display. When your test succeeds, save your configuration before proceeding to the next steps.

Click Insert Table or Column under the Database Map section to add a section for our Projects table:
Add Table

Note the Select Database Table button at the right of the Table Name field. Click it and the Database Tree opens in the taskpane:
Database Tree

If you double-click Projects in the Database Tree, the Table Name field will populate:
Table Field

Now, in the Node Path field next to the Table Name, click the Select Schema Node button, which opens the Schema Tree:
Schema Tree

Double-click the node associated with the first repeating group (my:Project) to populate the Node Path field:
Node Path field

To start adding our columns, select the top Insert Table or Column directly under the Table Name field.
Type field

For Type, select Column and map a column to a field in your form. You can type in the column name, of course, but if you select it from the Database Tree, the DB Type is selected for you. Also, it is more fun. The Node Path, too, can be typed in or selected from the Schema Tree. Needless to say, you can XPath up that Node Path all you want, which is good news since I have two fields in my form that I'd like to map that are not children of the table level Node Path.
Column Mapping

After mapping all the fields to our Projects table, the map looks like this:
Projects table mapped

That was almost too easy. Good news, adding the Issues table will be even more straighforward! Select Insert Table or Column directly under Description (as if adding another column) and for Type select Table:
Add child table

The Table Name will be Issues and the Node Path will be my:Projects/my:Project/my:Issues/my:Issue (note that the Node Path is to the nested repeating group). Select Insert Foreign Key below Column Name and put the ReportId column from the Issues table into the Column Name field and the ReportID column from the Projects table into the Parent Column Name field:
Foreign Key Mapping

All that is left to do is map those Issues columns to the fields in the Issue group. Select Insert Table or Column directly below Insert Foreign Key to add columns:
Issues table mapped

Our completed mapping:
Full Map

We are all done with mapping. Save your configuration, return to the form Catalog, and fill out your Status Report. I am going to put in three different projetcts, and add several issues to one project:
Filled out form

Now, submit the form and gleefully run off and check your SQL Tables -- I'll do the same.
Projects Table with Data

Issues table with dat

Comments

 

Recent URLs tagged Infopath - Urlrecorder said:

Pingback from  Recent URLs tagged Infopath - Urlrecorder

October 1, 2008 11:01 PM
 

Hilary Stoupa said:

In an earlier post , we looked at mapping data from nested repeating tables using DBXL v2.2. In that

January 27, 2012 2:40 PM

About Hilary Stoupa

I wandered into development after working as a business process analyst for a global manufacturing company. I create InfoPath solutions for our clients as well as work as a developer on company tools that extend InfoPath. I've also been instrumental in creating the InfoPath Master Class training provided by Qdabra.

Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.