Steps to Create a Workflow in AEM

Create a Workflow in AEM is the basic requirement which is expected now a days from a AEM Developer. It is quite simple to create a workflow in AEM and most of us are notl able to answer questions on it because we never got an opportunity to work on it or explore AEM workflow models.

After completing this tutorial you will be able to answer what are :

Basics of AEM Workflow Model


Creating a workflow allows user to define and execute a series of steps. In AEM we call workflow as Workflow models .Below are the basic terms used in aem workflow model.

  • Model : It is made up of WorkflowNodes and WorkflowTransitions. Workflow models are versioned. Running Workflow Instances keep the initial workflow model version that is set when the workflow is started.
  • Step : There are different types of workflow steps:
    • Participant (User/Group): These types of steps generate a work item and assigns it to a user or group. A user must complete the work item to advance the workflow.
    • Process (Script, Java method call): This type of step is executed automatically by the system. An ECMA script or Java class implements the step.
      Container (Sub Workflow): This step starts another workflow model.
    • OR Split/Join: Uses logic to decide which step to execute next in the workflow.
    • AND Split/Join: Executes multiple steps simultaneously.
      All the steps share the following common properties: Autoadvance and Timeout alerts (scriptable).
  • Transition : Defines the link between two consecutive steps.
  • WorkItem : A workflow instance can have one or many WorkItems at the same time (depending on the workflow model).
  • Payload : References the resource that has to be advanced through a workflow.
    The payload implementation references a resource in the repository (by either a path or an UUID) or a resource by a URL or by a serialized java object. Referencing a resource in the repository is very flexible and in conjunction with sling very productive: for example the referenced node could be rendered as a form.
  • Lifecycle : It is created when a new workflow is started and ends when the end node is processed.
    The following actions are possible on a workflow instance:

    • Terminate
    • Suspend
    • Resume
    • Restart

Completed and terminated instances are archived.

  • Inbox : Each logged in user has its own workflow inbox in which the assigned WorkItems are accessible.
  • Launcher : Allows you to define a workflow to be launched if a specific node has been updated.

When we create a new workflow model it consist of three default steps Flow Start ,Flow End and a dummy participant step named as step 1.

  • Flow Start and Flow End represent start and end of workflow.
  • Step1 Participant Step is assigned to admin user to configure a work step. We can edit or delete this step and add new steps as required.
Create a Workflow Model in AEM

create workflow in aem cq simply-cracked

  • The New Workflow dialog will open –> Type the Title and Name for your workflow and click OK.

create new workflow in aem cq simply-cracked

  • Your new workflow model appears in model tab.

Note:  Its a good practice to keep Name field in lowercase. As it acts as an id and doesnot accept space between words. Title acts as display name.

Add Steps to Workflow Model


Steps are used to represent an activity to be performed in Workflow. AEM comes with several pre-installed steps. When we open the workflow in edit mode, you can see all available processes that can be added to any step in workflow model.

  • Go to Model tab of workflow console. Either select workflow model right click on it and click edit or double click on selected workflow model.

edit workflow in aem cq simply-cracked

  • Drag a workflow model step from the sidekick and drop on indicated area as shown in below figure. A green check mark icon on the workflow component indicates its a valid drop zone.

add step in workflow model in aem cq simply-cracked

Note: Workflow steps always execute in the order in which they appear in workflow model.

Edit a Workflow Step


For editing a workflow step we can either use the default step1 or we can create a new one. In this example we are going to use the new participant step that we have created above .

For editing a workflow model step in AEM. Follow below steps:-

  • Right click and delete the default Step 1.
  • Right-click the participant step  and click Edit.

edit-workflow-process-in-aem-cq-aemcq5tutorials

  • Enter the values for Title and  Description and Enter timeout setting as immediate and handler as Auto Advancer to move to next step. For example  Validate Content.
    edit-workflow-step-in-aem-cq-aemcq5tutorials

 

  • Set the User/Group to admin, it will show you a drop down list of valid users and groups and click OK.

edit users in workflow step in aem cq simply-cracked

  • Drag an Or Split onto the workflow available above participant step in sidekick and position it between Validate Content workflow step and Flow End step.
    edit-workflow-or-split-process-in-aem-cq-aemcq5tutorials

 

  • Right-click the Or Split step and click Edit.
    edit-workflow-or-split-step-in-aem-cq-aemcq5tutorials

 

  • We can choose only one default route. For Branch 1, select Default Route. For Branch 2, ensure Default Route is not selected and Click OK.

edit workflow or split process default route in aem cq simply-cracked

  • You can provide a custom script in Script Text Area or create a ecma script under apps/<project>/workflow/scripts/ and enter the path in Script Path Text box.
  • Drag a Participant Step component to the left-hand branch, open the properties, specify the following property values, and click OK:
    • Title: Cancel Publish.
    • User/Group: admin.
    • Timeout: Immediate.
    • Timeout Handler: Auto Advancer.
  • Drag a Process Step to the right-hand branch, open the properties, specify the following values, and click OK:
    • Title: Publish Page
  • Process: Select Activate Page. This process publishes the selected page to the publisher instances. Check Handler Advance to auto move to Next Step.
    edit-workflow-process-step-in-aem-cq-aemcq5tutorials

 

  • Click Save on Top Left.

Note: Always click on Save other wise your changes won’t get reflected.

Start Workflow in AEM or Test Workflow in AEM

 

  • Start Workflow window will open.
    • Select Payload from content –> Click OK.
    • Enter Workflow Title. Ex. Training Workflow.
      start-workflow-select-payload-in-aem-cq-aemcq5tutorials

 

  • Click OK on Workflow Window.
  • Go to Instances tab. Your training workflow instance will be listed here. You can Terminate, Suspend or check status of workflow instance from here.
    start-workflow-instance-in-aem-cq-aemcq5tutorials

 

  • Right click on Training –> Click Open History

 

start-workflow-check-history-in-aem-cq-aemcq5tutorials

  • You have successfully executed workflow in AEM.
    start-workflow-open-instance-history-in-aem-cq-aemcq5tutorials
Spread the love
  •  
  •  
  •  
  •  
  •  
  •  

Leave a Reply

Your email address will not be published. Required fields are marked *