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:

  • 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.

Data Source
Recommended workflow
Form data model, OData, or any other third-party service
Option 1: You select form data model, OData, or any other third-party service as the data source. You generate an adaptive form with no data binding using the Automated Forms Conversion service. 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.
Option 2: You select form data model, OData, or any other third-party service as the data source. You generate an adaptive form with no data binding using the Automated Forms Conversion service. 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.
For step-by-step instructions to execute these workflows, see Use database, OData, or any third-party service as the data source.
JSON Schema
You select JSON schema as the data source. Based on the selected data source:
Option 1: You generate an adaptive form with no data binding using the Automated Forms Conversion service and configure JSON schema as the data source. You bind the adaptive form fields to JSON schema manually and use any of the supported protocols to prefill field values. Modify the field values, if necessary, and submit data to the crx-repository.
For step-by-step instructions to execute the workflows, see Use JSON schema as the data source.
Option 2: You generate an adaptive form with JSON data binding using the Automated Forms Conversion service. The prefill service and form submission function seamlessly. You do not need any configuration steps.
For step-by-step instructions to execute the workflows, see Use JSON schema as the data source.
XSD schema
You select XSD schema as the data source. Based on the selected data source, you generate an adaptive form with no data binding using the Automated Forms Conversion service and configure XSD schema as the data source. You bind the adaptive form fields to XSD schema manually and use any of the supported protocols to prefill field values. Modify the field values, if necessary, and submit data to the crx-repository.
For step-by-step instructions to execute the workflows, see Use XSD schema as the data source.

For more information on the Automated Forms Conversion service, 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

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

Get File

The PDF file serves as the input to the Automated Forms Conversion service. The service converts this file to an adaptive form. The following image depicts the sample loan application in a PDF format.

sample loan application form

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.

Sample data mysql

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

Get File

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

Get File

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.

Adaptive form with no data binding

After generating an adaptive form with no data binding, select a data source for the adaptive form:

NOTE
If the adaptive form that you convert using Automated Forms Conversion service contains multiple fields with the same name, ensure that those fields are bound to data source entities to avoid a possible data loss during submission.

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 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

Configure form data model

NOTE
Ensure that you add get and insert services to the form data model, configure, and test the services before executing the use case.

Execute the following steps:

  1. Select the converted sample loan application form available in the output folder and tap Properties.

  2. 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.

  3. Select the sample loan application form and tap Edit.

  4. In the Content tab, tap the configure icon:

    configure form container

    1. In the Basic section, select Form Data Model Prefill service from the Prefill Service drop-down list.

    2. In the Submission section, select Submit using Form Data Model from the Submit Action drop-down list.

    3. Select the data model using the Data Model to submit field.

    4. Tap done icon to save the properties.

  5. Tap the Applicant Name text box and select configure icon (Configure).

    1. In the Bind Reference field, select Applicant > Name, and tap done icon 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.

    Bind references

  6. Tap Preview to view the prefilled adaptive form field values.

  7. 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 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:

  1. Select the sample loan application form in the output folder and tap Edit.

  2. In the Content tab, tap the configure icon:

    configure form container

    In the Basic section, select Form Data Model Prefill service from the Prefill Service drop-down list.

  3. Tap the Applicant Name text box and tap Edit Rules.

    Edit rules to create data binding

  4. Tap Create on the Rule Editor page.

  5. On the Rule Editor page:

    1. 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.

    2. 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.

    3. 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.

    4. 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.

    5. Tap Done. Tap Done again on the Rule Editor page.

    Rule editor to bind references

  6. 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.
  7. 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 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:

  1. Select the converted sample loan application form available in the output folder and tap Properties.

  2. 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.

  3. Select the sample loan application form and tap Edit.

  4. Tap the Applicant Name text box and select configure icon (Configure).

    In the Bind Reference field, select Applicant > Name, and tap done icon 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.

  5. Select the converted sample loan application form available in the output folder again and select Preview > Preview with Data.

    Download sample data file

    Get File

  6. 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 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:

  1. Select the converted sample loan application form available in the output folder and tap Properties.

  2. 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.

  3. Select the sample loan application form and tap Edit.

  4. Tap the Applicant Name text box and select configure icon (Configure).
    In the Bind Reference field, select Applicant > Name, and tap Done Icon 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.

  5. Select the converted sample loan application form available in the output folder again and select Preview > Preview with Data.

    Download sample data file

    Get File

  6. 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 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.

Adaptive form with JSON binding

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. 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:

  1. Select the converted sample loan application form available in the output folder again and select Preview > Preview with Data.

    Download sample data file

    Get File

  2. 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));
    }
}
recommendation-more-help
c40c2ccf-3d1b-4b47-b158-c4646051b46c