XML Variables in AEM Workflow

Variables of type XML are typically used when you have an XSD based Adaptive Form and want to extract values from the Adaptive Form submission in your workflow.

The following video walks you through the steps needed to create variables of type String and XML and use them in your workflow.

The XML variable can be used to pre-populate the adaptive form or store the adaptive form’s submission data in your workflow.

String variable can be populated by Xpathing into the XML variable. This string variable is then typically used to populate the e-mail template placeholders in Send Email component

NOTE
If your adaptive form is not associated with XSD, then the XPath to get the value of an element will look like
/afData/afUnboundData/data/submitterName

The adaptive form data is stored under the data element as shown above. In the above XPath submitterName is the name of the text field in the Adaptive Form.

NOTE
AEM Forms 6.5.0 - When you are creating a variable of type XML to capture the submitted data in your workflow model, please do not associate the XSD with the variable. This is because when you submit XSD based Adaptive Form the submitted data is not compliant with the XSD. The XSD complaint data is enclosed in /afData/afBoundData/ element.
AEM Forms 6.5.1 - If you associate XSD with your XML variable you can browse the schema elements to do the variable mapping. You will not be able to access form data not bound to schema elements. If your use case is to access data bound to schema elements as well as unbound data, then do not bind schema with your XML variable in the workflow.You will have to use the approriate XPath expression to get to the data that you need

Creating XML Variables

Transcript
In this video we’re going to take a look at creating and using variables of type XML and String.
The ability to create variables was introduced in ADM form 6.5. To create variables, let’s create a work-flow model and open it Edit Mode, and then we go to this new tab which allows you to create variables. Click on Add Variable here and I’m gonna create a variable which will hold the SubmittedData of my Adaptive Form submissions. I will store it in variable type XML. So whenever you are creating an Adaptive Form, then it is either in an XML format or in an JSON format. So in this case, my submitted data will be in an XML format and that’s the reason my variable is going to be of type XML. I click on that here.
The next variable I am gonna create is to hold the submitter’s e-mail.
So this will hold the e-mail of the person submitting the form and this is going to be of type String.
So, so far I have created two variables; one to hold a submitted data and the other one to hold the submitter e-mail. So once these variables are created, the next step is to initialize these variables, and initialize these variables we make use of a new component called Set Variable.
Add the Set Variable to my work-flow model and open it’s configuration properties. Tap to the mapping tab and we map the variables here. The first variable that we need to map is the SubmittedData. So we map the SubmittedData here.
Select the mapping mode, it’s going to be Relative to Payload, and we do Data.xml. So make sure this Data.xml is the same name you provide when configuring your submit options of the Adaptive Form. The next mapping we need to do is for this SubmitterE-mail, so we click on the arrow, Mapping, the Map Variable. Scroll down here. We select the appropriate variable, here SubmitterE-mail. We select the mapping mode, is going to be XPath. We select the variable here, SubmittedData, and then we give the XPath for the XML variable, so here. So, the XML, the e-mail element, will be stored under /afData/afBoundData/Employee/Email. So employee and e-mail are my XML scheme elements, and afBound and afBoundData is something which AEM bounds add when an Adaptive Form based on a schemer is submitted. Then I do Save Here.
So, so far we updated two variables and then the mapping. The next thing we need to do is to use an Assign Task here, so I click here, and add an Assign Task here.
Open the pix configuration properties.
We select the Form/Document. Adaptive Form we’re gonna say available submitted to the workflow. So what this means is pick up the name of the Adaptive Form from the data that was submitted to the work-flow, and then for the Pre-population here, we’ll select a variable, and the variable is going to be SubmittedData here.
Then we go to the Assignee section; this is the same as AEM 6.4. We select a default here? or Administrator. Actions, we are not going to change anything. Advanced, we leave it as it is. Then we save it.
So to summarize, we created two variables, we initialized those variables and we used one of those variables in our Assign Task.

Using Schema with XML Variable

Mapping a XML variable with schema. Use this capability with AEM Forms 6.5.1 onwards

Transcript
In this video, we will take a look at associating schema with the variable of type XML. So in this work flow model I have two variables of type XML and of type string. Let’s open up the variable of type XML and if you noticed, I have associated a schema with my variable and this schema can be associated by clicking this selection dialog box and associating the schema from your repository. So when you are associating a schema with your XML variable, make sure the schema is the same schema that you have used to create your adaptive form.
So once you’ve associated your schema with the variable, the next step is to initialize the variables here. So the first thing that I have done is initialized my submitted data variable with the Data.XML that is available Relative to the Payload. This happens every time an adaptive form is submitted and the Data.XML is created Relative to the Payload. The next step is to initialize the submitter email variable here. And to do that I have clicked on the map variable here and select the variable called SubmitterEmail. We select the mapping mode. Since our variable is of type XML, we select XPath as the mapping mode. You select the variable here, SubmittedData. Since our submitted data which is of type XML and is backed by a schema, I can open this to open up the elements in the schema and I select the appropriate element here. In this case, it’s going to be email. And then click on save, here. So this way you can easily initialize a string variable with an element from a schema, as long as the XML variable is backed by that schema.
And then I save my setting.

Using the variable in send email

Transcript
In this video, we will take a look at using the SubmitterEmail. Mainly, one that was created in the previous video. To use the SubmitterEmail, I’ve added a Send Email component to my workflow. Let’s go ahead and configure its properties.
So, the Email Details is the Email Subject, here, “Your Time Off Request.” We select an appropriate HTML template.
I have added an HTML template under my libs, fd, dashboard, templates, email. I select my confirmation.txt email template, and then go to the Sender Details. Here, I give in some address here, admin@aemforms.com.
Recipient Details, recipient’s email address, you’re going to operate it using the variable that we created, so we selected the variable here, and we select SubmitterEmail variable. So this way, you can now use a variable of type string, and populate it with the SubmitterEmail, and use that variable in a recent email component.
Then we save here, and then we sync the workflow. So when you will submit a reactive form, which is configured to submit to this workflow, this workflow will get three guards: the variables will be initialized, assign task will be created, and once the assign task is completed, the Send Email step will then be triggered.

To get the assets working on your system, please follow the following steps:

recommendation-more-help
8de24117-1378-413c-a581-01e660b7163e