API to invoke form data model service from adaptive forms api-to-invoke-form-data-model-service-from-adaptive-forms
Adobe recommends using the modern and extensible data capture Core Componentsfor creating new Adaptive Formsor adding Adaptive Forms to AEM Sites pages. These components represent a significant advancement in Adaptive Forms creation, ensuring impressive user experiences. This article describes older approach to author Adaptive Forms using foundation components.
Overview overview
AEM Forms enables form authors to further simplify and enhance the form filling experience by invoking services configured in a form data model from within an adaptive form field. To invoke a data model service, you can either create a rule in the visual editor or specify a JavaScript using the guidelib.dataIntegrationUtils.executeOperation
API in the code editor of the rule editor.
This document focuses on writing a JavaScript using the guidelib.dataIntegrationUtils.executeOperation
API to invoke a service.
Using the API using-the-api
The guidelib.dataIntegrationUtils.executeOperation
API invokes a service from within an adaptive form field. The API syntax is as follows:
guidelib.dataIntegrationUtils.executeOperation(operationInfo, inputs, outputs)
The structure of the guidelib.dataIntegrationUtils.executeOperation
API specifies details about the service operation. The syntax of the structure is as follows.
var operationInfo = {
formDataModelId,
operationTitle,
operationName
};
var inputs = {
inputField1,
inputFieldN
};
var outputs = {
outputField1,
outputFieldN
}
The API structure specifies the following details about the service operation.
Sample script to invoke a service sample-script-to-invoke-a-service
The following sample script uses the guidelib.dataIntegrationUtils.executeOperation
API to invoke the getAccountById
service operation configured in the employeeAccount
form data model.
The getAccountById
operation takes the value in the employeeID
form field as input for the empId
argument and returns employee name, account number, and account balance for the corresponding employee. The output values are populated in the specified form fields. For example, the value in name
argument is populated in the fullName
form element and value for accountNumber
argument in account
form element.
var operationInfo = {
"formDataModelId": "/content/dam/formsanddocuments-fdm/employeeAccount",
"operationName": "getAccountDetails"
};
var inputs = {
"empid" : employeeID
};
var outputs = {
"name" : fullName,
"accountNumber" : account,
"balance" : balance
};
guidelib.dataIntegrationUtils.executeOperation(operationInfo, inputs, outputs);
Using the API with callback function using-the-api-callback
You can also invoke the form data model service using the guidelib.dataIntegrationUtils.executeOperation
API with a callback function. The API syntax is as follows:
guidelib.dataIntegrationUtils.executeOperation(operationInfo, inputs, outputs, callbackFunction)
The call back function can have success
and failure
callback functions.
Sample script with success and failure callback functions callback-function-success-failure
The following sample script uses the guidelib.dataIntegrationUtils.executeOperation
API to invoke the GETOrder
service operation configured in the employeeOrder
form data model.
The GETOrder
operation takes the value in the Order ID
form field as input for the orderId
argument and returns order quantity value in the success
callback function. If the success
callback function does not return the order quantity, the failure
callback function displays the Error occured
message.
success
callback function, the output values do not populate in the specified form fields.var operationInfo = {
"formDataModelId": "/content/dam/formsanddocuments-fdm/employeeOrder",
"operationTitle": "GETOrder",
"operationName": "GETOrder"
};
var inputs = {
"orderId" : Order ID
};
var outputs = {};
var success = function (wsdlOutput, textStatus, jqXHR) {
order_quantity.value = JSON.parse(wsdlOutput).quantity;
};
var failure = function(){
alert('Error occured');
};
guidelib.dataIntegrationUtils.executeOperation(operationInfo, inputs, outputs, success, failure);