Workflows are typically used to route submitted data for review and approval. Workflows are created using the workflow editor in AEM. The Workflows can be triggered on Adaptive Form submission.
Please make sure you have a working instance of AEM Forms. Please follow the installation guide to install and configure AEM Forms
The following video explains the creation of Review and Approval workflow using AEM Forms Components
Hi, in this video, we will create an AEM workflow to handle this adaptive form submission. The workflow will be triggered when the user clicks the submit button. In the workflow we will also out this form to the appropriate person for review and approval, depending on the value of this grand total field.
By default, the submitted data from the adaptive form submission is stored in an XML format. It can also be stored in json format if the adaptive form is based on json schema, or it is based on a form data model. Since our adaptive form is not based on any XML schema, the submitted data will be stored in an XML format and the entire submitted data will be stored under the afUnboundData node. Under that is a node called data. And under that you will see the submitted data from the adaptive form. So these are the element county. And under that there’s a value Alameda, means that there’s a field called county in your adaptive form and the value is Alameda. So as a best practice, we recommend you to name your fields appropriately so that it’s easier to understand the element names and its values. So in our workflow, we will extract the value from the grand total element and route the form appropriately to the right person.
So to create an AEM workflow, I’ve logged into my AEM instance as an administrator, and I’m going to go into the tools menu, click on the workflow tab and click on the models. So here I’m going to create a new workflow or a workflow model by clicking on the create and create model. Give a meaningful title. So I’m going to call my workflow review submitted data and click on done. So this creates our workflow model. Let’s go and add some variables or some steps to this particular workflow model. So by default, when you create a workflow models, it has a step one. So as part of building your workflow, we’ll add some more steps to this workflow. And on the left hand side are the various workflow components that you can take advantage of when you’re building your workflow model. You can filter these workflow components by its category. So for example, if you filter by forms workflow, it will only list you the workflow components which are specific to AEM forms.
And on the left hand side here allows you to create variables. So the variables are typically used in your workflow and these variables hold the submitted data or some values from the submitted data. So let’s go ahead and create our first variable to hold the submitted data. And we’re going to call it submitted data here.
So if you remember, our adaptive form was not based on any schema, hence the submitted data will be of type XML. So we’re going to select the type XML and leave the description in the schema part blank and create your variable. The next variable that will go into create is to hold the grand total.
Yeah, that’s the grand total and it is going to be of type long, right? So, so far we have created two variables, one for holding the submitted data from the adaptive form. And other one is to hold the grand total. So from the submitted data, we’ll extract the value of the element grand total and store that value in this variable. So to do that, the first thing we need to do is to insert a component called set variable, which allows us to initialize these variables. So, search for set variable component here and drag it to the, make it the first step in your workflow. So make it your first step. And you can delete this step one. We don’t need this for our workflow, right? So this is our set variable component, which allows us to initialize the variables. So let’s go ahead and initialize these two variables that we have. Go to the mapping step and click on mapping, map variables, and select the variable that you want to initialize. In this case, it’s submitted data and the mapping mode, the mapping mode is going to be related to payload. So what that means is when you submit the adaptive form, there will be a file called data.XML, which will be stored relative to the payload. And this data.XML file is the same name that we will use when configuring the adaptive form to trigger the AEM workflow. The next variable that we need to initialize is going to be the, grand total fields. So here we go to the grand total element and the mapping mode is going to be XPath because of our submitted data is of type XML.
And the variable here is going to be submitted data. And here we need to provide deep XPath for the grand total elements. So if you remember, the submitted data is going to look like this, and we need to XPath into this grand total element here and to XPath, we can write our XPath expression here. So this is my XPath expression. So if you see it drills down under afUnboundData, under the data element, there’s an element called grand total. That is what we are going to specify in our workflow model. So here we go and specify that and save your settings. So, so far we have created two variables and initialize those two variables.
The next thing we need to do is to assign the task to the appropriate user depending on the value of this grand total element.
Since we need to route the adaptive form based on the value of the grand total, we need to create what we call as an split condition in our workflow. So let’s go ahead and add the Or Split component here. So this allows us to create multiple branches in your workflow and depending on the condition, the various branches will be executed. So let’s go ahead and configure the Or Split component here. So let’s first give a meaningful name here.
“Route To The Correct User.” And by default, the Or Split component has two branches. And we can specify which branch to execute based on a condition. To specify a condition, there are these three options here. The easiest is to use the rule definition, which allows you to create a business rule using a graphical user interface. So click on this here. So what we want to do is to create a rule based on the grand total, based on the value of the grand total and the grand total is a workflow variable. And here we can say, if it is greater than, greater than 10,000 or we can add another condition here, is equal to 10,000. So all we are doing is creating a rule. If the grand total is greater than 10,000 or the grand total is equal to 10,000, then follow this part in my workflow. So let’s go ahead and rename this branch as well here.
So we rename this branch.
If grand total is equal to or greater than 10,000. And then for the second branch here, we’ll create another condition, here. Second branch. Again, we go to the rule definition, open up, and here we’ll say if the grand total is less than 10,000.
So if the grand total is less than 10,000, then follow this route here. So if we can rename this branch here.
It’s less than 10,000. If you wanted to add some more branches, you can do so by clicking on this add branch button here. So then save this. So, so far we have added a split condition in our workflow, and that split condition has two branches. If the grand total is greater than 10,000, it goes this route. If the grand total is less than 10,000, it goes this route. So in each of these branches, we can add as many workflow steps as you want. So the first thing we need to add here is to add and assign task component here. So let’s go ahead and add an assigned task.
So assigned task component allows someone to review the submitted data and we’ll add the same assigned task component here as well.
In this video, we’re going to configure our assigned tasks component that was added our workflow. So I’m going to open the assign task component and open up its configuration properties.
As you can see, the component has five tabs and each of these steps have various settings that you can use to customize or configure your assigned task component. So the first thing we need to do is to provide a meaningful title here, give a meaningful description. And here, if you want, you can specify the due date associated with this particular assigned tasks. So in our case we’re going to leave it as off. The next thing we are doing is to associate an adaptive form with the assigned task. So what that does is, it opens up the form that you have configured here when the user is interacting with the task. So in our case, we are going to say that use an adaptive form that was submitted to the workflow. And that particular adaptive form will be opened when the user is interacting with this assigned task. And then every form needs to have some data. And what we are saying here is, use the data in the variable called submitted data to pre-populate the adaptive form that is associated with this particular task. And in a similar manner, when the user has finished interacting with the task, store the form data in a variable called submitted data.
The next thing we’re going to do is to configure the assignee, meaning the user that is going to interact with that task. So that user can either be specified by to a specific user, meaning you hand quote the user or the user can be specified dynamically using custom code. In our case, we’re going to hand quote the user and you select the user by typing in the user’s name here and selecting the appropriate user.
Then there are some additional properties that you can specify by giving the user the option to share the inbox or to allow the assignee to share the inbox via inbox sharing. We are not going to use any of these options for now. And then, in the action step, this specifies what actions the user has when he’s interacting with this particular task. So by default, we provide you these three actions submit, save and reset. But in our case, we’re going to add two custom actions here. And those two custom actions are approve and reject. And each of these actions are associated with the Coral icon called check and the close. AEM provides a number of Coral UI icons. And those icons are listed here and you can use whichever icon you feel appropriate with that particular action.
The next thing I wanted to talk about was the route variable. So when the user has finished interacting with the task, he would have selected one of these two options to complete the task, either approve or reject. And you will typically store that action in a variable. And that variable is called UserActionTaken. And that’s a variable of type string which I had created here. So we will take a look at using this route variable or the UserActionTaken in the next video. And in the advanced tab we are not going to modify any of those default settings. We’re not going to check any of these options. We can leave them as blank. So once your assigned tasks type is called is configured. The next video, we will show you how to use the action taken, use the action taken variable and route the form accordingly.
In this video, we will add a routing condition based on the action taken by the user in the assigned task step here. So to do that, I’m going to add Or Split component. This is the same component that we added earlier in our workflow. And we’re going to configure this component here by giving a meaningful split name. And this component is going to have two branches, one branch for the approved action. If the user selects the approve action in the assigned task, it will go this particular route and that’s the name here, approve. And the second branch is going to be called reject. So if the user has selected the reject action in the assigned task, it will go this particular route, here, so. And then we need to specify a routing expression. And the easiest way to specify a routing expression is to use the rule definition builder here.
We’re going to use the UserActionTaken. Remember, this is the variable that will hold the action taken by the user while interacting with the assigned tasks steps. So we’re going to drag and drop that here. And we’re going to say if it is equal to, and select approve.
Sorry, select approve and save your action. In a similar manner, do the similar thing for your reject route.
Drag the user action.
Is equal to, reject. Save done and then save your settings here. So, so far based on the approve or reject action, we have created two branches. And in the next video, we’ll add some more components to these individual branches. So if the user clicks on the approve button, what do you want to do? And if the user clicks on the reject button, what do we want to do? So I have completed the workflow by adding generate document of record component under the approved branch and send email component under the reject branch. At a high level, gender document of record, creates a PDF from the data that was submitted from the adaptive form.
So this PDF is typically called a document of record. So in the generate document of record configuration properties, we are saying use the adaptive form submitted to the workflow and use the data that is stored in the variable called submitted data and generate a document of record or the PDF and store that PDF under the payload folder of the AEM workflow in the AEM repository and store that in a file called DoR.PDF.
I’m not going to go into the details of configuring send email component here. We have extensive documentation and also a video on configuring and using send email component. I encourage you to take a look at that. And also I’m not going to configure the other route where the grand total was less than $10,000. It’s up to you how you want to configure this. But as a practice exercise, I encourage you to configure this route based on what you have learned so far. So this concludes our video on creating review workflow on adaptive form submission. In the next video, we will see how to configure an adaptive form to trigger this particular workflow. And we’ll also see the end user experience in interacting with the adaptive form, through the inbox. -