{"id":4177,"date":"2017-06-09T09:34:07","date_gmt":"2017-06-09T04:04:07","guid":{"rendered":"\/?p=4177"},"modified":"2019-12-16T17:46:04","modified_gmt":"2019-12-16T12:16:04","slug":"workflow-in-aem","status":"publish","type":"post","link":"https:\/\/www.argildx.us\/technology\/workflow-in-aem\/","title":{"rendered":"Workflow in AEM – Beginners’ Journey to Create a Workflow"},"content":{"rendered":"
In this blog, we will take a beginner’s journey on how to create a workflow in AEM, a launcher and custom steps involved in it.<\/p>\n
Let us begin by understanding workflows.<\/p>\n
In AEM, a workflow is a well-defined series of steps that allows users to automate the activities in the CMS instance. It consists of various steps, including people (participants), procedures (process) or some tools. The workflow can either be sequential or parallel, when multiple procedures can run parallel to each other. In short, an workflow in AEM is similar to a flowchart which describes the series of procedures to be executed by multiple participants to achieve a desired outcome.<\/p>\n
There are many out-of-the-box workflow models readily available for use and we can even write custom workflows which can be tailored as per the business needs of the company.<\/p>\n
There are a plethora of use cases for writing workflows depending on the business needs.<\/p>\n
For example, the process of publishing a page can be customized and tailored for inclusion of some special participants that need to approve the request for activation or send a mail after approval or rejection.<\/p>\n
A workflow model is a container or blueprint of the workflow that combines the workflow steps and link them logically.<\/p>\n
List of workflows can be seen on http:\/\/<host>:<port>\/libs\/cq\/workflow\/content\/console.html<\/p>\n
<\/p>\n
Figure 1: AEM Workflow Console<\/span><\/p>\n <\/p>\n Figure 2: Tabs in Workflow Console<\/span><\/p>\n These are the tabs that contain the information about the workflows. <\/span><\/p>\n Let\u2019s have a look at one of the practical examples of workflow in AEM. To create a new workflow we can add the title and the name (cannot contain spaces) of the workflow by clicking on New tab.<\/span><\/p>\n <\/p>\n Figure 3: Create a new Workflow Model<\/p>\n Thereafter, we can edit the workflow created to customize it. This is the default view of the workflow wherein there is a start and an end node with a default participant step.<\/span><\/p>\n <\/p>\n Figure 4: By default view of workflow<\/span><\/p>\n We can view the logical layout of the workflow in the console whereas to see the node structure stored for the workflow we can see \/etc\/workflow\/models\/sample_workflow.<\/span><\/p>\n <\/p>\n Figure 5: Node structure of workflow in CRX<\/span><\/p>\n It contains metadata about the workflow stored in JCR. We can notice flow and model nodes. It has the nodes between start and end node present in the workflow. The model node has all the steps added in the workflow marked as nodes along with the transitions they have between them. We can see the metadata of node 6 in the snapshot since it is a process step having title as Publish Page.<\/span><\/p>\n We can see the running instance of the workflow under \/etc\/workflow\/instance path in CRX.<\/span><\/p>\n <\/p>\n Figure 6: Nodes in trigger workflow instance<\/span><\/p>\n This is an example of trigger workflow having data (metadata and payload of which workflow instance is working upon), history, metadata of a particular step and work Items associated with the workflow.<\/span><\/p>\n There are many workflow nodes that can be dragged and dropped such as Participant step, process step, and split, or split, dialog participant step, form participant step, container step, goto step etc.<\/span><\/p>\n <\/p>\n Figure 7: Participant<\/span> Step<\/p>\n <\/p>\n Figure 8: Process Step<\/span><\/p>\n Now, to add our own process in the list we have to make a workflow process and register it as a service in java and can add the logical code that will execute on this process step. <\/span><\/p>\n This code snippet shows the basic skeleton of a workflow process that it required for process step.<\/span><\/p>\n @Component<\/b> will register our Java class as a component with the properties that enables it immediately and helps it get the metadata provided by the execute method of WorkflowProcess class. <\/span><\/p>\n @Service<\/b> will register our Java class as a service to be used in the Workflow process.<\/span><\/p>\n @Properties<\/b> will add certain properties such as process.label which will show our class in the process list of the process step. The value of this property will be shown in the drop down list.<\/span><\/p>\n The Java class should implement WorkflowProcess interface and give definition to execute method. This method provides three arguments namely WorkItem, WorkflowSession, MetaDataMap. <\/span><\/p>\n There can be many other types of steps that can be configured within the workflow and can be tailored using java code, scripts, parameters etc. to provide the desired functionality.<\/span><\/p>\n <\/p>\n Figure 9: OR Split (marked with green)<\/span><\/p>\n <\/p>\n Figure 10: ECMA script written for branch 1 (set as default route).<\/span><\/p>\n We can write different condition for branch 2 or can upload a script. <\/span><\/p>\n This code snippet gets the model of the child workflow that needs to be invoked. Thereafter, the data of the workflow is created which is used to start the workflow in the current session.<\/span><\/p>\n<\/li>\n Workflow launchers can be used to trigger the workflow based on some event that can be specified in the launcher. We can add a launcher under the Launcher tab.<\/p>\n <\/p>\n Figure 11: Creation of Launcher for Workflow in AEM<\/span><\/p>\n Hope you understood the basics of creating workflow in AEM and try to implement this in one of the use cases you experience.<\/span><\/p>\n We can explore workflows in detail in future articles.<\/span><\/p>\n\n\n Other articles related to workflow in AEM: In this blog, we will take a beginner’s journey on how to create a workflow in AEM, a launcher and custom steps involved in it. Let us begin by understanding workflows. What is a workflow in AEM? In AEM, a workflow is a well-defined series of steps that allows users to automate the activities in … Read more<\/a><\/p>\n","protected":false},"author":10,"featured_media":6664,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","content-type":"","footnotes":""},"categories":[66],"tags":[25,1704,78,1702,79,80],"yst_prominent_words":[1568,1569,1566,1701,1124,1110,1119,1109,1121,1567,1118,1111,1120,1125,1112,1700,1113,1565,1122,1123],"acf":[],"yoast_head":"\n\n
Examples of workflow in AEM<\/b><\/h5>\n
Workflow Nodes<\/b><\/h5>\n
\n
\n
\n
\n
@Component(immediate = true, enabled= true, metatype = true)\n@Service(WorkflowProcess.class)\n@Property(name = \"process.label\", value = \"Create Page Service\", propertyPrivate = true)\npublic class TriggerWorkflow implements WorkflowProcess {\n \n @Override\npublic void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args)\n throws WorkflowException {<\/pre>\n
\n
String payload = workItem.getWorkflowData().getPayload().toString();<\/pre>\n
\n
\n
\n
\n
WorkflowModel workflowModel = workflowSession.getModel(\"\/etc\/workflow\/models\/childworkflow\/jcr:content\/model\");\nWorkflowData workflowData = \nworkflowSession.newWorkflowData(\"JCR_PATH\", \"\/content\/bhf\/poc\/sampleWorkflowPage\");\n \nworkflowSession.startWorkflow(workflowModel, workflowData);\n<\/pre>\n
\n
Workflow Launchers<\/h5>\n
\n
1) Triggering a Workflow using Event Listeners in AEM<\/u><\/a>
2) Workflow Purge Scheduler<\/u><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"