Posts in Category "XML Schema"

Populate a Drop Down List in LiveCycle Designer with Dynamically Generated XML

One way to populate a Drop-down List on a LiveCycle form is using XML binding. In the situation explained below, the XML document is dynamically generated and bound to the form’s data model within a LiveCycle process by querying the database.

Situation:

Querying a database for all the supervisors and their ID. Then populate a drop-down list on the form with a single Data Connection.

4 Steps:

  1. Create a DataConnection on your form with an XSD that includes unbound occurrence of the list items.
  2. Add a Drop-down list to the form
  3. Bind the data to the drop-down list
  4. Create an Action Profile process to pre-populate the form with data from the database

1. Create a DataConnection on your form with an XSD that includes unbound occurrence of the list items.

Since the drop down list is only one field in the form and we are using a single data connection to bind data to the form, insert the following element node for the Supervisor Drop-down List. The selected fields are to be used to hold the currently selected value in the drop-down list.

<xs:element name="supervisorList">
      <xs:complexType>
              <xs:sequence>
                   <xs:element name="supervisor">
                         <xs:complexType>
                             <xs:sequence maxOccurs="unbounded">
                                 <xs:element name="supervisorID" type="xs:int"/>
                                 <xs:element name="supervisorName" type="xs:string"/>
                             </xs:sequence>
                         <xs:complexType>
                     </xs:element>
              </xs:sequence>
       </xs:complexType>
 </xs:element>
<xs:element name="selectedSupervisorName" type="xs:string"/>
<xs:element name="selectedSupervisorID" type="xs:int"/>

To add the Data Connection to your form:

  • Right click on the Data View Tab
  • Select New Data Connection
  • Select XML Schema
  • Browse to the XSD in your Application
  • Select the root node and Press OK

2. Add a Drop-down list to the form

From the Object Library in LiveCycle Designer, drag the Drop-down List object on to the form.

3. Bind the data to the drop-down list

Under the Object Panel, click on the Binding Tab. Bind the item to the selectSupervisorID in the Data Connection.

After adding data binding, the Specify Item Values text should become a green hyperlink. If link text is not green, ensure that dynamic properties is turned on. Click on the Specify Items Value.

Fill out the fields as shown above. Notice the [x] in the Items field. This enables all the elements to be loaded in to the list.

4. Create an Action Profile process to pre-populate the form with data from the database

In order to pre-populate the Drop-down list before the user sees the form:

  1. Create an Action Profile for the form that will call a Prepare Data Process
  2. Inside the Prepare Data Process, Create an XML variable called SupervisorList
  3. Inside the Prepare Data Process, Query the Database and Build an XML Variable using the Service Query for Multiple Rows as XML Service (Foundation/JdbcService).  After applying a SQL Statement to retreive the Supervisor ID and Supervisor Name from the database, click on the elipses button next to XML Information and fill it according to the image below according to your XSD.
  4. Set the Output for Step 3 Service to be the XML Variable created in Step 2.
  5. Bind the XML to the XSD element used in the forms DataConnection using setValue

Now, when the user pulls up the form in Workspace, it comes pre-populated with all of the Supervisors Names. The value for each field will be the Supervisor ID in this case.