You're viewing help content for version:
- 6.4
- Older Versions
This tutorial is a step in the Create your first Interactive Communication series. It is recommended to follow the series in chronological sequence to understand, perform, and demonstrate the complete tutorial use case. |
AEM Forms data integration module allows you to create a form data model from disparate backend data sources such as AEM user profile, RESTful web services, SOAP-based web services, OData services, and relational databases. You can configure data model objects and services in a form data model and associate it with an adaptive form. Adaptive form fields are bound to data model object properties. The services enable you to prefill the adaptive form and write submitted form data back to the data model object.
For more information about form data integration and form data model, see AEM Forms Data Integration.
This tutorial walks you through the steps to prepare, create, configure, and associate a form data model with an interactive communication. At the end of this tutorial, you will be able to:
- Set up the database
- Configure MySQL database as data source
- Create form data model
- Configure form data model
- Test form data model
The form data model looks similar to the following:
Before you begin, ensure that you have the following:
- MySQL database with sample data as stated in the Set up the database section.
- OSGi bundle for MySQL JDBC driver as explained in Bundling the JDBC Database Driver
A database is essential to create an Interactive Communication. This tutorial uses a database to display Form Data Model and persistence capabilities of Interactive Communications. Set up a database containing customer, bills, and calls tables.
The following image illustrates sample data for the customer table:

The calls table includes the call details such as call date, call time, call number, call duration, and call charges. The customer table is linked to the calls table using the Mobile Number (mobilenum) field. For each mobile number listed in the customer table, there are multiple records in the calls table. For example, you can retrieve the call details for the 1457892541 mobile number by referring to the calls table.
The bills table includes the bill details such as bill date, bill period, monthly charges, and call charges. The customer table is linked to the bills table using the Bill Plan field. There is a plan associated to each customer in the customer table. The bills table includes the pricing details for all the existing plans. For example, you can retrieve the plan details for Sarah from the customer table and use those details to retrieve pricing details from the bills table.
You can configure different types of data sources to create a form data model. For this tutorial, you will configure the MySQL database that is configured and populated with sample data. For information about other supported data sources and how to configure them, see AEM Forms Data Integration.
Do the following to configure your MySQL database:
-
Install JDBC driver for MySQL database as an OSGi bundle:
- Log in to AEM Forms Author Instance as an administrator and go to AEM web console bundles. The default URL is http://localhost:4502/system/console/bundles.
- Tap Install/Update. An Upload / Install Bundles dialog appears.
- Tap Choose File to browse and select the MySQL JDBC driver OSGi bundle. Select Start Bundle and Refresh Packages, and tap Install or Update. Ensure that the Oracle Corporation's JDBC Driver for MySQL is active. The driver is installed.
-
Configure MySQL database as a data source:
- Go to AEM web console at http://localhost:4502/system/console/configMgr.
- Locate Apache Sling Connection Pooled DataSource configuration. Tap to open the configuration in edit mode.
- In the configuration dialog, specify the following details:
- Datasource name: You can specify any name. For example, specify MySQL.
- DataSource service property name: Specify name of the service property containing the DataSource name. It is specified while registering the data source instance as OSGi service. For example, datasource.name.
- JDBC driver class: Specify Java class name of the JDBC driver. For MySQL database, specify com.mysql.jdbc.Driver.
- JDBC connection URI: Specify connection URL of the database. For MySQL database running on port 3306 and schema teleca, the URL is: jdbc:mysql://[server]:3306/teleca?autoReconnect=true&useUnicode=true&characterEncoding=utf-8
- Username: Username of the database. It is required to enable JDBC driver to establish a connection with the database.
- Password: Password of the database. It is required to enable JDBC driver to establish a connection with the database.
- Test on Borrow: Enable the Test on Borrow option.
- Test on Return: Enable the Test on Return option.
- Validation Query: Specify a SQL SELECT query to validate connections from the pool. The query must return at least one row. For example, select * from customer.
- Transaction Isolation: Set the value to READ_COMMITTED.
Leave other properties with default values and tap Save.
AEM Forms provide an intuitive user interface to create a form data model from configured data sources. You can use multiple data sources in a form data model. For the use case in this tutorial, you will use MySQL as the data source.
Do the following to create form data model:
-
On AEM author instance, navigate to Forms > Data Integrations. The default URL is http://localhost:4502/aem/forms.html/content/dam/formsanddocuments-fdm.
A computed property is the one whose value is computed based on a rule or an expression. Using a rule, you can set the value of a computed property to a literal string, a number, result of a mathematical expression, or the value of another property in the form data model.
Based on the use case, create the usagecharges child computed property in the bills data model object using the following mathematical expression:
- usage charges = call charges + conference call charges + SMS charges + mobile internet charges + roaming national + roaming international + VAS (all these properties exist in the bills data model object)
For more information on the usagecharges child computed property, see Plan the Interactive Communication.
-
In the mathematical expression, select callcharges and confcallcharges as first and second objects, respectively. Select plus as the operator. Tap within the mathematical expression and tap Extend Expression to add smscharges, internetcharges, roamingnational, roamingintnl, and vas objects to the expression.
The following image depicts the mathematical expression in the rule editor:
Once the data model objects have been defined, you can build associations between them. The association can be one-to-one or one-to-many. For example, there can be multiple dependents associated with an employee. It is referred to as one-to-many association and depicted by 1:n on the line connecting associated data model objects. However, if an association returns a unique employee name for a given employee ID, it is referred to as one-to-one association.
When you add associated data model objects in a data source to a form data model, their associations are retained and displayed as connected by arrow lines.
Based on the use case, create the following associations between the data model objects:
Association | Data model objects |
1:n | customer:calls (Multiple calls can be associated with a customer in a monthly bill) |
1:1 | customer:bills (One bill is associated with a customer for a particular month) |
-
In the Add Association pane:
- Specify a title for the association. It is an optional field.
- Select One to Many from the Type drop-down list.
- Select calls from the Model Object drop-down list.
- Select get from the Service drop-down list.
- Tap Add to link the customer data model object to calls data model object using a property. Based on the use case, the calls data model object must be linked to the mobile number property in the customer data model object. The Add Argument dialog box opens.
-
In the Add Argument dialog box:
- Select mobilenum from the Name drop-down list. The mobile number property is a common property that is available in customer and calls data model objects. As a result, it is used to create an association between customer and calls data model objects.
For each mobile number available in the customer data model object, there are multiple call records available in the calls table. - Specify an optional title and description for the argument.
- Select customer from the Binding To drop-down list.
- Select mobilenum from the Binding Value drop-down list.
- Tap Add.
- Select mobilenum from the Name drop-down list. The mobile number property is a common property that is available in customer and calls data model objects. As a result, it is used to create an association between customer and calls data model objects.
-
In the Add Association pane:
- Specify a title for the association. It is an optional field.
- Select One to One from the Type drop-down list.
- Select bills from the Model Object drop-down list.
- Select get from the Service drop-down list. The billplan property, which is the primary key for the bills table, is already available in the Arguments section.
The bills and customer data model objects are linked using the billplan (bills) and customerplan (customer) properties respectively. Create a binding between these properties to retrieve the plan details for any customer available in the MySQL database. - Select customer from the Binding To drop-down list.
- Select customerplan from the Binding Value drop-down list.
- Tap Done to create a binding between the billplan and customerplan properties.
The following image depicts the associations between the data model objects and the properties used to create associations between them:
After creating associations between the customer and other data model objects, edit the customer properties to define the property based on which the data is retrieved from the data model object. Based on the use case, mobile number is used as the property to retrieve data from the customer data model object.
You can test the data model object and services to verify that the form data model is configured properly.
Do the following to run the test:
Form data model editor allows you to generate sample data for all data model object properties, including computed properties, in a form data model. It is a set of random values that comply with the data type configured for each property. You can also edit and save data, which is retained even if you regenerate the sample data.
Do the following to generate, edit, and save sample data: