Expand my Community achievements bar.

Adding/Populating Subforms from SQL Table Records

Avatar

Level 2

Hello,

I have a form I produced on LiveCycle Designer ES2.   I don't have a LiveCycle Server product. I am learning how to code using LiveCycle.

The form has a subform ("Contactssubform") with the following fields: "FirstName", "MiddleName", and "LastName".   There is a dataconnection ("ContactsSQLTableDataConnection") between the form and a SQL table ("ContactsSQLTable") - the table has fields "TableFirstName", "TableMiddleName", and "TableLastName.  I want to be able to press a button on the form, and have the the # of instances of the Contacts subform be the same as the # of records in ContactsSQLTable.   I then want the each Contactssubform instance filled with a record from ContactsSQLTable.

How do I code this in the Button click event?

I've done a lot of research in the forums/internet to try and figure out the code, but haven't been able to do so.  I would have thought one could do something like this:

-Loop through the records of the ContactsSQLTable

-Add an Instance of the Contacts Subform for each record

-Fill in the fields in the subform instance with the data form the table record

e.g.

xfa.sourceSet.ContactsSQLTableConnection.Records.first;

for (x=1;x<xfa.sourceSet.ContactsSQLTableConnection.Records.Length;x++)

{

xfa.Formpage.Contactssubform.AddInstance(1);

xfa.Formpage.Contactssubform.FirstName = xfa.sourceSet.ContactsSQLTableConnection.Record.TableFirstName;

xfa.Formpage.Contactssubform.MiddleName = xfa.sourceSet.ContactsSQLTableConnection.Record.TableMiddleName;

xfa.Formpage.Contactssubform.LastName = xfa.sourceSet.ContactsSQLTableConnection.Record.TableLastName;

xfa.sourceSet.ContactsSQLTableConnection.Records.next;

}

I see instead I should be looping through the nodes of the data connection(?)  Having trouble understanding how to do that.

Thank you for any assistance with this.

Andrew

2 Replies

Avatar

Level 2

Another way I tried to go about adding/populating subforms from the table was by making the subform a child of a flowed subform, and then binding the flowed subform to the table DataConnection.  I checked off "Repeat Subform for Each Data Item" for the flowed subform.  However, the flowed subform did not repeat for each table record-I thought it would do that.

Avatar

Level 1

Greendesk123,

Your second method i think is the best way to go. Be sure that the subform itself set to flow instead of position. Next are you sure that your data connection is returning mutliple records? I don't have a lot of experience with this type of data connection, but with a simple XML file, it works very easily as long as the bindings are correct.