Simple Paid Time Off Request Workflow

In this article, we look at a simple workflow used for requesting Paid Time Off. The business requirements are as follows:

  • User A requests time off by filling in an adaptive form.
  • The form is routed to AEM admin user (In real life it is routed to the submitter’s manager)
  • Admin opens the form. Admin should not be able to edit any information filled by the submitter.
  • Approver section should be visible to the approver(In this case it is the AEM admin user).

To accomplish the above requirement, we use a hidden field called initialstep in the form and its default value is set to Yes.When the form is submitted, the first step in the workflow sets the value of initialstep to No. The form has business rules to hide and show the appropriate sections based on the initialstep value.

Configure Form to Trigger AEM Workflow

In this video we will take a look at the Time Off Request Form, and the business rules that were used to author this particular form. So this form is a fairly basic form that is used to request time off. This form has two panels, one is for the Submitter Details, that will capture the name and the department of the person requesting the time off, and the start date and end date. And then the second section is the Approved By section, where the approver of this request can approve or decline, and also add some comments related to that particular request. The two business rules are, the Approved By section needs to be hidden or shown, depending on the person viewing the form, and there need to be a mechanism by which the Submitter Details section needs to be disabled if this form is being viewed by an approver. So lets take a look at the first business requirement, where we need to hide or show the Approved By section. So to do that I have created an initial step, text field in my Submitter Details panel. Let’s take a look at this configuration. So this field will be hidden from both the submitter as well as the approver, and that is accomplished by clicking this checkbox, which allows us to hide the object. And the default value of this field is going to be Yes. Because when the first time a person is requesting a time off the value of this field will be Yes, and then depending on this particular value we will hide or show the Approved By section. And to do that, we have created a simple rule on the Approved By section here, so if you open up this rule on the Approved By section, which shows that we need to show this Approved By section when the initials steps value is equal to No, if not we need to hide that particular section. So when the form is rendered for the very first time the initial step value is Yes, and when the value is Yes, we hide the Approved By section. The next rule or the business rule that we need to take care of is to make the Submitter panel disabled so the person approving the request will not be in the position to change the values. So to do that we have another rule on the initial step here, so when the initial step value is equal to No, then we disable the Submitter Details panel. So whenever a person is reviewing this time off request, he will not be able to modify the data entered by the submitter in the Submitter Details. The next section that we need to take care of is the configuration or configuring a form to trigger an AEM blockflow. So to do that, I’ve opened up the form container, and go into the submission properties here. You select the Submit Appropriate submit action, in this case it’s going to be AEM blockflow. Select your workflow model and specify the data filepath. The data filepath is the name of the file that will hold this submitted data. The name of the file here is irrelevant, you can call it anything you want, data.XML, data.json or its totally up to you. The only thing that you need to remember is make sure you use the same file name in our workflow as you will see in the second video. We are not going to use the attachment part and the document of record part here. So now that our form is configured, we have authored the necessary business rules to hide and show the Approval section, let’s take a look at the form at run time. So I’m going to preview this form here.
So think of this as a person requesting a time off, because I’m requesting a time off I don’t need to see the Approved By section here, so here I’m going to, I can enter my details here.
So once I’ve entered the time off request details, I can submit this form. And on submission the workflow will be triggered. We will take a look at the workflow in the next video. Thank you.

Workflow walkthorugh

When you submit an adaptive form to triggered AEM Workflow certain nodes are created in the CRX repository, so let’s take a look at those nodes here so you open up the war folder and under the war folder there’s a folder called workflow, open that workflow folder and under that you will see instances, server zero and you see a bunch of folders with the various dates, so every time you restart your AEM server it will create a folder with that particular date, so under our current date which is 8/11 you will see that there are three instances of helpx workflow that were triggered so far on this particular date, so helpx workflow is the name of the workflow and it appends it with a number to indicate how many times it has been invoked for that particular date, so let’s open up helpx workflow three and here you will see that there are some folders created out of the box, so under the data folder there’s a folder called payload and if you open that payload there’s a property called part, with a particular value in the CRX folder, so let’s open up this particular part here.
I will open that part and that part will hold the payload, for the payload of a workflow typically contains attachments or the submitted data of the form, so in our case we’re gonna have the submitted data of the form that is stored in data.XML. Remember this data.XML is the same name that we used when configuring our adaptive form submission options, so this data.XML has the data that was captured in the adaptive form and for instance we have the submitters name the submitters department and it also has the initial step who’s value is set to null.
The initial steps value was set to null using our workflow and that workflow is over here, this is a very simple workflow with two steps, the first step is the process step which allows us to execute some custom code, so this custom code was given to you as part of the set value bundle that you installed and deployed before you started this article or tutorial and in this case we’re gonna pass in an argument here is the initial step that is the xpart of the initial step and what value you want to set to the initial step element in that XML, so in this case we’re gonna set the value as null. Based on the value of the initial step our approval section would be shown or hidden from the person opening the form, so the next step in our workflow is an assigned task step, if you see its configuration properties.
We have changed the title to manager review and we have associated the adaptive form here by opening up this dialogue box and then we have, used the data.XML to prepopulate our adaptive form, so typically in a workflow you would want to prepopulate the form with the data submitted in the previous step of the workflow so that is done by using the data.XML which is relative to the payload, so remember again that data.XML is the same name that we used when configuring our adaptive form, if this name is different your adaptive form will not prepopulate with the information entering the previous step of the workflows. The next tab is the assign new task. Here we can determine whom this task will be routed to, in our case we have hard coded it to the user admin but in real life scenario you will typically use the dynamically assign to user or a group and then look up the person who has submitted the form, look up the person’s manager and assign that task to that particular manager, and then here we have actions available to the user, submit, save and reset so this is our simple workflow. Now let’s take a look at the managers view of the form when the task is assigned to that person so here I have logged in as admin, I’ve opened up my inbox and I’ll open this task here with the form so this is the manager’s review and I will see this form has now the approver’s section and the submitters section is disabled, I am not able to modify these values and here I should be able to approve or decline the request and I can type in some additional comments and once I am satisfied with this one I can submit this particular form to complete the workflow.

Submitter’s view of the Time Off Request form


Approver view of the form


In the approver view, the approver is not able to edit the submitted data. There is also a new section meant for Approvers only.

To test this workflow on your system, please follow the steps mentioned below: