Recommended data source-based prefill and submit workflows for adaptive forms recommended-data-source-btased-prefill-and-submit-workflows-for-adaptive-forms
You can use any of the following data sources with adaptive forms converted using Automated Forms Conversion service (AFCS):
- Form data model, OData, or any other third-party service
- JSON schema
- XSD schema
Based on the data source, you can choose to generate an adaptive form with or without a data model.
This article describes the recommended workflows to prefill field values and submission options after selecting a data source and generating an adaptive form using the conversion service.
For more information on the Automated Forms Conversion service (AFCS), see the following articles:
The information provided in this article is based on the assumption that anyone reading it has basic knowledge of adaptive forms concepts.
Pre-requisites pre-requisites
- Configure an AEM author instance
- Configure Automated Forms Conversion service (AFCS) on the AEM author instance
Sample adaptive form sample-adaptive-form
To execute the use cases to prefill field values in an adaptive form and submit them to the data source, download the following sample PDF file.
Sample loan application form
The PDF file serves as the input to the Automated Forms Conversion service (AFCS). The service converts this file to an adaptive form. The following image depicts the sample loan application in a PDF format.
Prepare data for form model prepare-data-for-form-model
AEM Forms Data Integration allows you to configure and connect to disparate data sources. After generating an adaptive form using the conversion process, you can define the form model based on a form data model, XSD, or a JSON schema. You can use a database, Microsoft Dynamics, or any other third-party service to create a form data model.
This tutorial uses the MySQL database as the source to create a form data model. Create a loanapplication schema in the database and add an applicant table to the schema based on the fields that are available in the adaptive form.
You can use the following DDL statement to create the applicant table in database.
CREATE TABLE `applicant` (
`name` varchar(45) DEFAULT NULL,
`address` varchar(45) DEFAULT NULL,
`phonenumber` int(11) NOT NULL,
`email` varchar(45) DEFAULT NULL,
`occupation` varchar(45) DEFAULT NULL,
`annualsalary` varchar(45) DEFAULT NULL,
`familymembers` int(11) DEFAULT NULL,
PRIMARY KEY (`phonenumber`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
If you are using an XSD schema as the form model to execute the use cases, create an XSD file with the following text:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://adobe.com/sample.xsd"
xmlns="http://adobe.com/sample.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="sample" type="SampleType"/>
<xs:complexType name="SampleType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="phonenumber" type="xs:int"/>
<xs:element name="email" type="xs:string"/>
<xs:element name="occupation" type="xs:string"/>
<xs:element name="annualsalary" type="xs:string"/>
<xs:element name="familymembers" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Or download the XSD schema to the local file system.
Sample loan application XSD schema
For more information on using XSD schema as the form model in adaptive forms, see Creating adaptive forms using XML schema.
If you are using a JSON schema as the form model to execute the use cases, create a JSON file with the following text:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"loanapplication": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"address": {
"type": "string"
},
"phonenumber": {
"type": "number"
},
"email": {
"type": "string"
},
"occupation": {
"type": "string"
},
"annualsalary": {
"type": "string"
},
"familymembers": {
"type": "number"
}
}
}
},
"type": "object",
"properties": {
"employee": {
"$ref": "#/definitions/loanapplication"
}
}
}
Or download the JSON schema to the local file system.
Sample loan application JSON schema
For more information on using JSON schema as the form model in adaptive forms, see Creating adaptive forms using JSON schema.
Generate adaptive forms with no data binding generate-adaptive-forms-with-no-data-binding
Use the Automated Forms Conversion service to convert the sample loan application form to an adaptive form with no data binding. Ensure that you select the Generate adaptive form(s) without data bindings check box to generate the adaptive form with no data binding.
After generating an adaptive form with no data binding, select a data source for the adaptive form:
Use database, OData, or any third-party service as the data source sqldatasource
Use Case: You generate an adaptive form with no data binding using the Automated Forms Conversion service (AFCS) and configure MYSQL database as the data source. You bind the adaptive form fields to form data model entities manually and use the Form Data Model Prefill Service option to prefill field values. You use the Submit using Form Data Model option to submit the adaptive form.
Before executing the use case:
Based on the use case, create the loanapplication form data model and bind read service argument to a Literal value. The phone number literal value must be of one of the records configured in the applicant schema of the MySQL database. The services use the value as an argument to fetch details from the data source. You can also select User Profile Attribute or Request Attribute from the Binding To drop-down list
Execute the following steps:
-
Select the converted sample loan application form available in the output folder and tap Properties.
-
Tap the Form Model tab, select Form Data Model from the Select From drop-down list, and tap Select Form Data Model to select the loanapplication form data model. Tap Save & Close to save the form.
-
Select the sample loan application form and tap Edit.
-
In the Content tab, tap the configure icon:
-
In the Basic section, select Form Data Model Prefill service from the Prefill Service drop-down list.
-
In the Submission section, select Submit using Form Data Model from the Submit Action drop-down list.
-
Select the data model using the Data Model to submit field.
-
Tap to save the properties.
-
-
Tap the Applicant Name text box and select (Configure).
- In the Bind Reference field, select Applicant > Name, and tap to save the properties. Similarly, create a data binding for the Address, Phone Number, E-mail, Occupation, Annual Salary (in dollars), and No. of dependent family members fields with the form data model entities.
-
Tap Preview to view the prefilled adaptive form field values.
-
Modify the field values, if necessary, and submit the adaptive form. The field values are submitted to the MySQL database. You can refresh the applicant table in the database to view the updated values in the table.
Use Case: You generate an adaptive form with no data binding using the Automated Forms Conversion service (AFCS) and configure MYSQL database as the data source. You bind the adaptive form fields using the rule editor to prefill field values. Modify the field values, if necessary, and submit data to the crx-repository.
Execute the following steps to use rule editor to invoke form data model service to bind fields and prefill values in an adaptive form:
-
Select the sample loan application form in the output folder and tap Edit.
-
In the Content tab, tap the configure icon:
In the Basic section, select Form Data Model Prefill service from the Prefill Service drop-down list.
-
Tap the Applicant Name text box and tap Edit Rules.
-
Tap Create on the Rule Editor page.
-
On the Rule Editor page:
-
Select a state for the Applicant Name text box. For example, is initialized, which results in execution of the Then condition when you render the form in Preview mode.
-
In the Then section, select Invoke Service from the Select Action drop-down list. All services on your Forms instance display in the drop-down list.
-
Select a Get service from the section listing the form data models. The Input field displays phonenumber, which is the primary key defined for the applicant data model. The system retrieves and prefills the values in the adaptive form for fields in the Output section based on this field.
-
Create a binding for the adaptive form fields with the form data model entities using the Output section. For example, bind Applicant Name adaptive form field with the name entity.
-
Tap Done. Tap Done again on the Rule Editor page.
-
-
Tap Preview to view the prefilled adaptive form field values.
note note NOTE Ensure that the Return Array Property is set to OFF for the get service property in the form data model associated with the adaptive form. -
Modify the field values, if necessary, and submit the adaptive form. The submitted data is available at the following location in the crx-repository:
http://host name:port/crx/de/index.jsp#/content/forms/fp/admin/submit/data/latest file available in the folder
Use JSON schema as the data source jsondatasource
Use Case: You generate an adaptive form with no data binding using the Automated Forms Conversion service (AFCS) and configure JSON schema as the data source. You bind the adaptive form fields to JSON schema manually and use the Preview with data option to prefill field values. Modify the field values, if necessary, and submit data to the crx-repository.
Before executing the use case, ensure that you have:
Execute the following steps:
-
Select the converted sample loan application form available in the output folder and tap Properties.
-
Tap the Form Model tab, select Schema from the Select From drop-down list, and tap Select Schema to upload the demo.schema JSON schema saved on the local file system. Tap Save & Close to save the form.
-
Select the sample loan application form and tap Edit.
-
Tap the Applicant Name text box and select (Configure).
In the Bind Reference field, select Applicant > Name, and tap to save the properties. Similarly, create a data binding for the Address, Phone Number, E-mail, Occupation, Annual Salary (in dollars), and No. of dependent family members fields with the JSON schema entities.
-
Select the converted sample loan application form available in the output folder again and select Preview > Preview with Data.
Download sample data file
-
Modify the field values, if necessary, and submit the adaptive form. The submitted data is available at the following location in the crx-repository:
http://host name:port/crx/de/index.jsp#/content/forms/fp/admin/submit/data/latest file available in the folder
Use XSD schema as the data source xsddatasource
Use Case: You generate an adaptive form with no data binding using the Automated Forms Conversion service (AFCS) and configure XSD schema as the data source. You bind the adaptive form fields to XSD schema manually and use the Preview with data to prefill field values. Modify the field values, if necessary, and submit data to the crx-repository.
Before executing the use case, ensure that you have:
Execute the following steps:
-
Select the converted sample loan application form available in the output folder and tap Properties.
-
Tap the Form Model tab, select Schema from the Select From drop-down list, and tap Select Schema to upload the loanapplication XSD schema saved on the local file system. Select root element for the XSD schema and tap Save & Close to save the form.
-
Select the sample loan application form and tap Edit.
-
Tap the Applicant Name text box and select (Configure).
In the Bind Reference field, select Applicant > Name, and tap to save the properties. Similarly, create a data binding for the Address, Phone Number, E-mail, Occupation, Annual Salary (in dollars), and No. of dependent family members fields with the XSD schema entities. -
Select the converted sample loan application form available in the output folder again and select Preview > Preview with Data.
Download sample data file
-
Modify the field values, if necessary, and submit the adaptive form. The submitted data is available at the following location in the crx-repository:
http://host name:port/crx/de/index.jsp#/content/forms/fp/admin/submit/data/latest file available in the folder
Generate adaptive forms with JSON binding generate-adaptive-forms-with-json-binding
Use the Automated Forms Conversion service (AFCS) to convert the sample loan application form to an adaptive form with data binding. Ensure that you do not select the Generate adaptive form(s) without data bindings check box while generating the adaptive form.
Use JSON schema as the data source jsonwithdatabinding
Use Case: You generate an adaptive form with JSON data binding using the Automated Forms Conversion service (AFCS). The prefill service and form submission function seamlessly. You do not need any configuration steps.
Before executing the use case, ensure that you have an adaptive form with data binding.
Execute the following steps:
-
Select the converted sample loan application form available in the output folder again and select Preview > Preview with Data.
Download sample data file
-
Modify the field values, if necessary, and submit the adaptive form. The submitted data is available at the following location in the crx-repository:
http://host name:port/crx/de/index.jsp#/content/forms/fp/admin/submit/data/latest file available in the folder
Convert submitted adaptive form JSON data to XML format convert-submitted-adaptive-form-data-to-xml
When you enter values in adaptive form fields and submit it, the data is available in JSON format in the crx-repository. You can convert the format of JSON data to XML either using org.apache.sling.commons.json.xml API or the following sample code:
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.commons.json.xml.XML;
public class ConversionUtils {
public static String jsonToXML(String jsonString) throws JSONException {
//https://sling.apache.org/apidocs/sling5/org/apache/sling/commons/json/xml/XML.html#toString(java.lang.Object)
//jar - http://maven.ibiblio.org/maven2/org/apache/sling/org.apache.sling.commons.json/2.0.18/
//Note: Need to extract boundData part before converting to XML
return XML.toString(new JSONObject(jsonString));
}
}