Previous Next JavaScript must be enabled to correctly display this content

## 20.15.1.2 Creating a Task Definition

Create a Task Definition from the Shared Components page, under the Workflows and Automations heading.

To create a task definition:

1. Select an application.
2. Navigate to the Task Definitions page:
   1. On the application home page, select Shared Components.
   2. Under Workflows and Automations, select Task Definitions.
3. Click Create.
   The Create Task Definition wizard appears.
4. Specify the task definition name and define the metadata.
   1. Name - Enter a name for the new Task Definition.
   2. Type - Select `Approval Task` for tasks with an outcome, or `Action Task` for tasks with no outcome.
   3. Subject - Provide a subject for the task definition.
      For example, `Purchase Requisition for Order &ORDER_ID.`, where `ORDER_ID` is a defined parameter of the task definition. `ORDER_ID` is substituted with the parameter value on task creation.
      For more on substitution strings, see Task Substitution Strings and Bind Variables.
   4. Static ID - Provide a static ID for this task definition. The static ID is used when creating the task with the `APEX_HUMAN_TASK` package (`APEX_HUMAN_TASK.CREATE_TASK`).
   5. Priority - Set the priority for the task. Choose a number between 1 and 5, where 1 is Urgent and 5 is Lowest. The default priority is 3 - Medium.
   6. Potential Owner - The user who owns the task.
      To determine potential owners dynamically, edit the participants in the Task Definition Details. For approval tasks, the user who initiates the task cannot own that task, even if they are listed as a Potential Owner. For action tasks, the user who initiates the task can also complete the task.
   7. Business Admin - The user who has administrative rights on all tasks for this task definition.
      To determine business administrators dynamically, edit the participants in the Task Definition Details.
5. Click Create.
   The Task Definition details page opens.
6. (Approval tasks only) Set the Initiator Can Complete toggle:
   - On - The task initiator can also approve or reject the task.
   - Off - (Default.) The task initiator is not allowed to approve or reject the task.
7. Set the Task Details Page Number. If a Task Details Page already exists for this application, enter the page number here. Otherwise, select Create Task Details Page to create a new page.
   The Task Details Page allows you to view the details of the task instance when the task is selected on the Unified Task List Report. See Editing the Task Details Page.

   Tip:

   If your task details page includes a form region that needs the primary key to look up the row, edit the saved task definition to include `&Pxx_ID=&DETAIL_PK.` in the Task Details URL.
8. Set the Actions Source - Specify the source of the data that is evaluated when the task actions execute.
   These actions are based on tables or SQL queries. An Actions SQL Query can reference the bind variable `:APEX$TASK_PK` to access the value of the primary key in the task detail row.
9. Set Due on Type:
   - Interval - The ISO or SQL format duration that specifies when a task is due. Only positive interval values are allowed.
   - SQL Query - The SQL query that returns a valid due date for the task.
   - Function Body - The function body that returns a valid due date for the task.
   - Expression - The PL/SQL expression that returns a valid due date for the task.
   - Scheduler Expression - The Database Scheduler calendaring syntax that returns a due date. For example, `first Friday of the month at 4:00 p.m.`.
10. After setting the Due on Type, set the Expiration Policy:
    - None - After the due date, the task stays in its current state, and owners can still approve or reject the task. This is the default setting.
    - Expire - After the due date, the task expires. Expired tasks cannot be approved or rejected.
    - Renew - After the due date, the task expires, and a new task is created from the same task definition. If you select Renew, set the Maximum Renewal Count to specify the maximum number of times a task is automatically renewed. A task can be renewed up to 99 times.
11. Specify the Vacation Rule Procedure, if applicable, in the format `[schemaName.[packageName]].procedureName`.
    The vacation rule procedure returns additional alternate participants for this task definition. It implements the following interface:

            procedure my_vacation_rule (
                p_param    in apex_human_task.t_vacation_rule_input,
                p_result  out apex_human_task.t_vacation_rule_output );

    For an example of a vacation rule procedure, see item-level help or Example: Adding a Vacation Rule Procedure.

    Tip:

    A vacation rule defined at the task definition level overrides a vacation rule defined at the application level.

To assign users to the Task Definition:

12. Click Add Participant.
13. Select the Participant Type:
    - Potential Owner
    - Business Administrator
    - Excluded Owner
    - Excluded Admin
    For approval tasks, the user who initiates a task cannot approve their own task unless the Initiator Can Complete property is enabled in the task definition. For action tasks, the user who initiates a task can own and complete their own task.
    Excluded owners cannot complete the task at runtime. Excluded admins cannot administer the task at runtime.
14. Set the Identity Type.
    - User
    - Authorization Scheme
    If the Participant Type is Excluded Owner or Excluded Admin, the Identity Type defaults to User.
15. If the Identity Type is User, set the Value Type:
    - Static
    - SQL Query
    - Function Body
    - Expression
    SQL Query, Function Body, and Expression all allow users to be dynamically selected, and can return a single user name or a comma-separated list of multiple user names.
16. If the Identity Type is Authorization Scheme, select the Authorization Scheme Value.
17. Click Create.
18. Set Parameters.
    1. Select Add Row and fill in the parameter fields.
    2. Static ID - Identifier used to reference the parameter.
    3. Label - A user-friendly name for the task parameter.
    4. Data Type - Choose `String`.
    5. Required - Specify whether the parameter is mandatory.
    6. Visible - Specify whether the parameter is visible in the task details page.
    7. Updatable - Specify whether the parameter can be updated in the Task Details page after the task is started.
    8. Comment (Optional) - Describe the parameter.

    Note:

    Parameters set in the Task Definition also need to be set in the page process. See Creating Tasks from Task Definitions.
19. Select Apply Changes to save all existing changes, and then click on the task definition name to continue editing.
20. Add Actions.
    1. Click Add Action.
       The Edit Action page opens.
    2. Name - Enter a name for the task definition action.
    3. Type - Select Execute Code, Send Email, or Send Push Notification.
       For Send Email, you can use predefined email templates with substitution strings. For example, you can configure a notification email to the initiator when a task is approved or rejected. For more information, see Managing Email Templates.
       If you have a plug-in set up for task definitions, you can use that plug-in here. For more information, see About Creating a Task Definition Process Plug-in.
    4. Execution Sequence - Specify the execution sequence. Actions are executed in numerical order from low to high.
    5. On Event - Select the event that triggers the action.
    6. Success Message - Enter a success message that indicates the action is successfully processed. The success message is included in the task history if the Log Messages When attribute in the Error Handling section is set to `All` or `Success`.
21. Configure the Action Type.
    - Set attributes for Execute Code:
      - Location - Specify whether your PL/SQL code is executed in the Local Database or on a REST Enabled SQL Service.
      - Language - Select the language used to evaluate the code.
      - Code - Provide the PL/SQL code to be executed.
        - Column values from the task definition action query are available as bind variables by column name, such as `:EMPNO` and `:ENAME`. For more on bind variables, see Task Substitution Strings and Bind Variables. You can expand the Examples section to see code examples.
    - Set attributes for Send Email:
      - From - The email address that displays as the sender of the email.
      - To - The email recipients.
      - Cc - The carbon copy email recipients.
      - Bcc - The blind carbon copy email recipients.
      - Reply To - The email address replies are sent to. If left blank, the From email is used.
      - Email Template - Choose an email template, and set the placeholder values. For more information, see Managing Email Templates.
      - Subject - The subject of the email.
      - Body Plain Text - The text of the email. Plain text is used if the recipient's email client does not support rich text. See the in-app help text for more details.
      - Body HTML - The HTML text of the email. See the in-app help text for more details.
      - Attachment SQL - Enter a SQL statement that returns one or more BLOBs that are attached to the email as files.
    - Set attributes for Send Push Notification:
      - To - User name of the application user who receives the push notification. To receive the notification, the user must have subscribed to the application first. User name is case sensitive.
      - Title - Title of the push notification.
      - Body - Body of the push notification.
      - Link Target - URL of the page that opens when the user clicks on the push notification. This defaults to the home page of the application. You can use the `&APP_ID.`, `&SESSION.`, and `&DEBUG.` substitution strings with `&COLUMN_NAME.` syntax to set the row ID or primary key on the target page, or to set additional attribute values. For more information, on URL syntax, see Understanding f?p URL Syntax.
22. Set up Error Handling:
    1. Error Message - Enter an error message that can be added to the task log if the action errors while executing. The error message is included in the task history if the Log Messages When attribute in the Error Handling section is set to `All` or `Failure`. Use `#SQLERRM#` as a placeholder for the actual ORA error message.
    2. Stop Execution on Error - Enable if processing for the current task stops after an error. Subsequent actions are not processed, and the task goes into the `ERRORED` state.
    3. Log Messages When - Specify the actions that are logged in the task history. You can choose between None, Success, Failure, and All. When actions are logged in the history, they include the Success Message or Error Message text.
23. Finish configuring the Action.
    1. Condition Type - Select a condition type that must be met for this action to be executed.
    2. Build Option - Select a build option for this action. Build options determine whether or not components in an application are enabled.
    3. Comments - Enter developer notes here. These comments only display in App Builder and are not visible in the application.
24. Click Create to go back to the Task Definition.
25. Add any comments for this task definition.
26. Click Apply Changes.

APEX creates the task definition.

Parent topic: Managing Task Definitions