Creating Workflow Models

Create a workflow model to define a series of steps to execute. New workflow models include Flow Start and Flow End steps that represent the beginning and end of the workflow. The model also contains an example Participant step named Step 1. The step is configured to assign a work item to the admin user.  Edit or delete this step, and add steps as required.

file
  1. Open the Workflow console. (http://localhost:4502/libs/cq/workflow/content/console.html)

  2. On the Models tab, click New. The New Workflow dialog opens.

  3. Type the title for your workflow and click OK.

The new model appears in the Models tab.

file

Adding a Step to a Model

Add steps to a model to represent an activity to perform. Several step components are installed with AEM. Each step performs a specific activity. When you edit a model, the available steps appear on the Components tab in Sidekick.

 

file

For information about the step components that are installed with AEM, see Workflow Steps Reference

At run time, steps are executed in the order in which they appear in the model. After adding step components, you can drag them to a different location in the model.

  1. On the Models tab of the Workflow console, select a workflow model and click Edit.
  2. Drag a worklfow step component from Sidekick to the model. A checkmark icon on the component indicates a valid drop location.
file

Editing a Workflow Step

Configure step components to change their behavior. Step components provide properties dialogs for configuring.

  1. Right-click a process step in the workflow model and click Edit:

    file
  2. Configure the step properties. For information about the properties of installed step components, see Workflow Steps Reference.

    file

Creating a Simple Workflow

To illustrate some of the possibilities for creating a workflow, the following example creates a variation of the Publish Example workflow.

  1. Right-click Step 1 and click Edit.
  2. Enter Validate Content for the Title and Description.
  3. Set the User/Group to /home/users/a/admin and click OK.
  4. Drag an Or Split onto the workflow and position it between Validate Content and Flow End.
  5. Right-click the Or Split step and click Edit.
  6. For Branch 1, select Default Route. For Branch 2, ensure Default Route is not selected.
  7. Click OK.
  8. 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: /home/users/a/admin
  9. Drag a Process Step to the right-hand branch, open the properties, specify the following values, and click OK:
    • Title: Publish Page
    • Process: Select Active Page. This process publishes the selected page to the publisher instances.
  10. Click Save.
file

Defining a Rule for an OR Split

OR splits allow you to introduce conditional processing paths into your workflow. To define an OR rule, proceed as follows:

  1. Create two scripts and save them in the repository, for example under /apps/myapp/workflow/scripts.
    Note: the scripts must have a function check() that returns a boolean.
  2. Edit the workflow and add the OR split to the model.
  3. Edit the properties of one branch of the OR split.
  4. Define the Default Route by setting the Value to true.
  5. As Rule, set the path to the script. For example: /apps/myapp/workflow/scripts/myscript1.ecma
  6. Edit the properties of the other branch of the OR split.
  7. As Rule, set the path to the other script. For example: /apps/myapp/workflow/scripts/myscript2.ecma
  8. Set the properties of the steps in each branch. Make sure the User/Group is set.

The following objects are available within ECMA scripts:

The following sample script returns true if the node is a JCR_PATH located under /content/geometrixx/en:

function check() {
    if (workflowData.getPayloadType() == "JCR_PATH") {
	     var path = workflowData.getPayload().toString();
	     var node = jcrSession.getItem(path);
	     
	     if (node.getPath().indexOf("/content/geometrixx/en") >= 0) {
	     	return true;
	     } else {
	     	return false;
	     }	
     } else {
     	return false;
     }
}

        

Las muestras de código se muestran con fines de ilustración únicamente.

Debugging and Testing Workflows

Refer to the section Debugging to start the AEM instance in debug mode.

You can display Debug messages related to workflows in the log files:

  1. In your browser, go to the Apache Felix Console and select Configuration.
  2. Select Apache Sling Logging Logger Configuration. Click Create.
  3. Set the Log Level to Debug.
  4. Set the Logger to com.mycompany.workflow.
  5. Click Save.
  6. When the development is finished, set the Log Level back to Info.

Test a new workflow as follows:

  1. Open the Workflow console; for example http://localhost:4502/libs/cq/workflow/content./console.html
  2. In the Models tab, right-click the model and select Start.
  3. Define the Payload and click OK.
  4. If one of the steps is a User Step, click the Inbox tab, select the step and perform the desired action.
  5. While running the workflow, monitor the log files.

Nota

It is a good practice when debugging a workflow to test the workflow with a  payload type that is different than the one for which it has been developed. For example, if you intend your workflow to deal with Assets, test it by setting a Page as payload and make sure that it does not throw errors.

Using workflows to process form submissions

  1. Open the Websites console.

  2. Open the page on which you want add the form.

  3. Drag a Form component from the Components tab in the Sidekick and place it in the page.

  4. Edit the Start of Form component that appeared in the page.

  5. Select the desired workflow from the available options under Start Workflow.

    file
  6. Click OK to confirm the new form configuration.

The form is now configured to be processed by the selected workflow. When users submit the form, a new workflow instance will be created, with the data of the form submission as its payload.

Collecting Data Using Forms and Workflows

With AEM you can associate a workflow with forms. It enables you to build processes in which visitors will input information based on multiple forms; for example, an online registration process.

In this section you will create a two steps process to display two characteristics of the "Product of the Day". In the first step, the author will fill out the first form to define the name of the product. In the second step, the author will fill out the second form and specify the designer of the product. The result will be displayed in the Product of the Day page.

Create the Product of the Day page

To create the Product of the Day page:

  1. Go to the Websites console.
  2. Create the Product of the Day page below Websites/Geometrixx Outdoors Site/Enlish/Equipment with the following property values:
    Title: Product of the Day
    Template: Content Page without Sidebar
  3. Open the new page. The two columns each contain a single paragraph with no text. Add the following text to the paragraphs:
    • Left-hand column: Name:
    • Right-hand column: Designed By:
  4.  Add a Text component from the General tab of Sidekick to each of the two columns, below the existing paragraphs.

 

file

Obtain the paragraph node names

Use CRXDE Lite to find the name of the nodes in the repository that are associated with the paragraphs that you added to the Product of the Day page.

  1. Open CRXDE Lite in your web browser. (http://localhost:4502/crx/de)
  2. In the node tree, expand the /content/geometrixx-outdoors/en/equipment/product-of-the-day/jcr:content/par node.
    Below the par node, the colctrl nodes represent the columns on the Product of the Day page, and the col_break nodes represent the end of the columns. The left-hand column is the first colctrl node, and the right-hand column is the second colctrl node.
  3. Note the name of the second text node after the first colctrl node. The second text node represents the empty text component that you added to the left-hand column.
  4. Note the name of the second text node after the second colctrl node. The second text node represents the empty text component that you added to the right-hand column.

In the following graphic, the text nodes are text_cee2 and text_a233. Your node names will likely have different characters following text_.

file

Create the first form (form1)

To create the first form (form1):

  1. Go to the Websites console.
  2. Create the page form1 below Websites/Geometrixx Outdoors Site/Enlish/Equipment with the following characteristics:
    • Title: form1
    • Template: Content Page without Sidebar
    Note: The location of the form pages is not important.
  3. Open form1 and delete the 2 Columns component.
  4. From the Form group in Sidekick, drag the Form component to the page.
  5. Edit the Start of Form component and set the following properties on the Advanced tab to link the form to a workflow:
    • Action Type: Edit Workflow Controlled Resource(s)
    • Form Identifier: form1
    Click OK.
  6. From the Form group in Sidekick, drag the Text Field component between the Start of Form and the End of Form bars of the Form component.
  7. Edit the Text Field component to specify the following property values:
    • Element Name: ./jcr:content/par/text_****/text

      text_**** is the name of the node that represents the empty paragraph on the Product of the Day page. In the previous example, the node name is text_cee2.

    • Title: Product Name:
    Click OK.
    When the form is submitted, the value in this field is stored in the <payload-path>/jcr:content/par/text_0/text node.
  8. Drag the Workflow Submit Button(s) component from Sidekick to immediately after the Text Field component. This component provides the submit button of the form.
file

Create the second form (form2)

To create the second form (form2):

  1. Go to the Websites console.
  2. Create the page form2 below Websites/Geometrixx Outdoors Site/English/Equipment with the following characteristics::
    • Title: form2
    • Template: Content Page without Sidebar

    Note: The location of the form pages is not important.

  3. Open form2 and delete the 2 Columns component.
  4. Drag the Form component from Sidekick to the page.
  5. Edit the Start of Form component and specify the following property values to link the form to a workflow:
    • Thank You Page (Form tab): {payload}.html
    • Action Type (Advanced tab): Edit Workflow Controlled Resource(s)
    • Form Identifier (Advanced tab): form2
    Click OK.
  6. Drag the Text Field component from Sidekick to between the Start of Form and the End of Form bars.
  7. Edit the Text Field component to specify the following property values:
    • Element Name: ./jcr:content/par/text_****/text

      text_**** is the name of the node that represents the empty paragraph on the Product of the Day page. In the previous example, the node name is text_a233.
    • Title: Developer Name:
    Click OK.
    When the form is submitted, the value in this field is stored in the <payload-path>/jcr:content/par/text_2/text node.
  8. Drag the Workflow Submit Button(s) component from the Sidekick to immediately after the Text Field component. This component provides the submit button of the form.
file

Create the workflow

To create the workflow:

  1. Go to the Workflow console.
  2. In the Models tab, create a new workflow model with the title Product of the Day.
  3. Edit the new workflow.
  4. Delete Step 1.
  5. Drag a Form Participant Step component to the workflow. Specify the following property values:
    • Title: Step 1
    • User/Group: /home/users/a/admin
    • Form path: /content/geometrixx-outdoors/en/equipment/form1
  6. Add a Form Participant Step component after Step 1 and specify the following property values:
    • Title: Step 2
    • User/Group: /home/users/a/admin
    • Form path: /content/geometrixx-outdoors/en/equipment/form2
  7. Save the workflow model.
file

Apply the workflow to the Product of the Day page

To apply the workflow to the Product of the Day page:

  1. Open the Product of the Day page in edit mode. If the page is still open from a previous procedure, reload it.
  2. In Sidekick, click the Workflow tab and select the Product of the Day workflow. Click Start Workflow.
  3. Open the Inbox page. (http://localhost:4502/libs/cq/workflow/content/inbox.html)
  4. Select the Step 1 item for the Product of the Day content, and click Open.
    The form1 page opens.
  5. In the Product Name box, type Abidjan Water Red, and click Next.
    The form2 page opens.
  6. In the Developer Name box, type Abidjan and click finish.
  7. The page Product of the Day opens and displays the information that you have entered through the two-step process.
file
​