Skip to Main Content

The Sample Workflow, Approvals, and Tasks app illustrates the key functionality of the Oracle APEX Workflow, Approvals, and Tasks components. It lets users manage requests to change an employee's salary, job, and bank acount, as well as request a new laptop, after getting the approval of an appropriate individual. Managers can also initiate a subordinate's appraisal process.

Overview

APEX workflow lets you automate business processes of any kind, including business logic, conditional branching, local or remote API invocation, time delays, email and push notifications, approvals, and action tasks to to be completed by end users. Using process plug-ins you can extend its core set of activities. APEX workflow components include:

  • The Workflow definition shared component and visual designer to configure the activities and flow of a business process, as well as its subject, participants, parameters, and variables. A workflow can optionally be related to a system of record table row by a Details Primary Key value.
  • The Workflow Console page type in the Create Page wizard to quickly create three kinds of pages to review and manage workflow instances
  • The Workflow page process to easily start, suspend, resume, or retry a workflow.
  • The APEX Workflow engine to execute individual workflow instances
  • A ready-to-use data model for workflows and database views to query their definitions and instances
  • The APEX_WORKFLOW package API for creating, retrieving, and managing workflows programmatically

Workflows

At design time, you'll create workflows, each of which is a shared component that defines:

  • a subject that summarizes the business process and can include parameter values,
  • a built-in detail primary key for the row of application data to which the workflow is related
  • an Additional Data table name or SQL query that uses the detail primary key value at runtime to retrieve related system-of-record data
  • the parameters to store data relevant to the workflow that cannot be queried from other existing tables
  • the users who can participate in the workflow as owners or admins, or the query/expression that will determine them at runtime
  • the activities and connections that determine the logical flow of the business process.
  • One workflow can call another using an Invoke Workflow activity, optionally waiting for it to complete and return out parameters

At runtime, the detail primary key, parameter values, and additional data table (or SQL query) columns are available to reference as substitution parameters in the workflow activities, and they are available to reference as bind variables in any dynamic task participant expressions and activity expressions or code blocks.

Workflow Console

The Workflow Console is a type of page the APEX Create Page wizard can create to show your users a list of workflows from any application in your workspace. Alternatively you can configure it to show only the workflows related to the current application if that better suits your requirements. The report context you choose at page creation time determines which tasks the generated page will show the current user:

  • "My Workflows" - workflows in which they are a participant
  • "Initiated Workflows" - workflows they created
  • "Admin Workflows" - workflows they are allowed to administer (e.g. change variable values, suspend, retry, etc. )

In addition, the wizard generates a second Workflow Details Page explained below. If you set the Include Dashboard Page switch to on, the wizard can also create a Workflow Dashboard Page containing a graphical overview of workflow instance activity over time. Once created, the workflow console page, workflow details page, and workflow dashboard pages can be customized like any other APEX page.

Workflow Details Page

The Workflow Details Page is shown to the end-user when they click on a particular workflow instance in the workflow console list page. It accepts the ID of a workflow instance as a hidden page item and displays an overview of information about the workflow instance identified by the ID passed in. It also shows:

  • the history of activities performed and their status (Waiting, Completed, Faulted, etc.)
  • the values of all of the parameters and variables
  • buttons allowing appropriate users to suspend, resume, terminate, or retry the workflow.
  • visual diagram of the workflow status

Workflow Dashboard Page

The Workflow Dashboard Page includes seven charts by default that give a graphical overview and details about Workflows by State, Active Workload, Fault Workload, and Performance.

Workflow Diagram Region

The Workflow Diagram region type lets a developer include a visual workflow diagram that illustrates the current status of a workflow instance and helps an end-user understand what particular path of activities have already been completed and if applicable, what activity the workflow instance is currently waiting on.

Workflow Page Processes

Use the Workflow process in a page to create a new workflow instance, by choosing the workflow definition and the Start type. Configure the optional Details Primary Key Item if appropriate and any required parameters the workflow may define. To further process the system-assigned unique ID of the workflow, configure a Workflow ID Item. Other avalable action types are Terminate, Suspend, Resume, or Retry.

Workflow Database Views

You can query the metadata about your workflow definitions from new views shown in the figure below. Use the APEX_APPL_WORKFLOWS view to query workflow definitions, and use its related child views to retrieve the metadata about the parameters, versions, variables, participants, activities, activity variables, branches, and transitions that comprise the workflow definition. Use the APEX_APPL_WORKFLOW_COMP_PARAMS view to query the parameter information about the workflow-related page processes in your pages. Use the APEX_WORKFLOWS view to query workflow instances, and use its related child views to query the workflow instance's activities, activity variables, version variables, parameters, participants, and audit information.

readme_workflowviews.jpg

APEX_WORKFLOW Package

The APEX_WORKFLOW package provides the PL/SQL API your application can use to programmatically create and manage workflows.

Overview

The APEX approvals and tasks features simplify creating apps requring any kind of end-user actions, including approvals. They include:

  • The Task Definition shared component to configure the subject, parameters, participants, and actions of a task. It can optionally be related to a system of record table row by a Details Primary Key value. Tasks can be either:

    • an action task, when only tracking a task's completion is important, or
    • an approval task, when an approved or rejected outcome is needed.
  • The Unified Task List page type in the Create Page wizard to quickly create three kinds of approvals "inbox" pages

  • The Generate Task Details Page button while editing a task to create a page showing task info, history, comments, and actions

  • The Human Task - Create and Human Task - Manage page processes to easily create and act on task instances in your pages

  • The APEX approval tasks engine to execute instances of approval and action tasks.

  • A ready-to-use data model for tasks and database views to query their definitions and instances

  • The APEX_APPROVAL package API for creating, retrieving, and managing tasks programmatically

  • An optional Task Vacation Rule Procedure that can be configured at application level or task definition level to implement custom handling of task participant reassignment due to staff vacations or other reasons.

Task Definition

At design time, you'll create task definitions, each of which is a shared component that includes:

  • a subject that summarizes the request for approval,
  • a built-in detail primary key for the row of application data to which the request is related
  • an action table name or SQL query that uses the detail primary key value at runtime to retrieve related system-of-record data
  • the parameters to store data relevant to the pending request that cannot be queried from other existing tables
  • the users who can participate in the task's approval process as approvers or admins, or the query/expression that will determine them at runtime
  • the actions that will be triggered when the state of the task changes, which can conditionally execute code or send email

At runtime, the detail primary key, parameter values, and action table (or SQL query) columns are available to reference as substitution parameters in the task's subject and email notifications, and they are available to reference as bind variables in any dynamic task participant expressions and action code.

Unified Task List

The Unified Task List is a type of page the APEX Create Page wizard can create to show your users a list of tasks requiring their attention from any application in your workspace. Alternatively you can configure it to show only the tasks related to the current application if that better suits your requirements. The report context you choose at page creation time determines which tasks the generated page will show the current user:

  • "My Tasks" - pending tasks requiring their approval
  • "Initiated Tasks" - tasks they created
  • "Admin Tasks" - tasks they are allowed to administer (e.g. change the due date, or explicitly assign)

Once created, the unified task list can be customized like any other APEX page.

Task Details Page

The Task Details Page is a type of page you can create by clicking on the Create Task Details Page button in the Task Definition editor. It accepts the ID of a task instance as a hidden page item and displays an overview of information about the particular task instance identified by the ID passed in. It also shows:

  • the values of all of the task parameters
  • the discussion thread of comments users have made during the approval process
  • the history of changes made to the task
  • buttons allowing appropriate users to claim, release, delegate, prioritize, approve, or reject the task.

Each task definition includes a reference to the task details page that it should use at runtime. While technically a single task details page could be used by all task definitions, in practice, you will most likely find it useful to create one task detail page per task definition and customize it to include additional information from your application data that will be useful to the approver of that specific task at hand.

Approvals Page Processes

Use the Human Task - Create process in a page to create a new task instance, passing in values for the detail primary key of the task as well as any required parameters the task may define. The Human Task - Manage process allows your pages to perform actions on existing tasks like approve, reject, comment, claim, delegate, release, cancel, invite a participant, or set the priority.

Task Database Views

You can query the metadata about your task definitions from new views shown in the figure below. Use the APEX_APPL_TASKDEFS view to query task definitions, and use its related child views to retrieve the metadata about the actions, parameters, and participants that comprise the task definition. Use the APEX_APPL_TASKDEF_COMP_PARAMS view to query the parameter information about the approval-related page processes in your pages. Use the APEX_TASKS view to query task instances, and use its related child views to query the task instance's history, parameters, comments, and participants.

readme_taskviews.jpg

APEX_HUMAN_TASK Package

The APEX_HUMAN_TASK package provides the PL/SQL API your application can use to programmatically create and manage tasks.

Task Vacation Rule Procedure

You can configure a task vacation rule procedure at application-level or task definition level. If configured at task definition level, that one takes precedence over an application-level one. The procedure receives an input record containing the static id of the task definition involved, task parameter values, and the list of original task participants. The procedure can use this information, along with any other application-specific data, to return a set of additional task potential owners and/or business administrators for the current task instance. The APEX engine engages your task vacation rule procedure at task instance creation and when a task is delegated to a new owner.

Overview

The Sample Workflow, Approvals, and Tasks application uses a copy of the data from the familiar EMP and DEPT tables, along with a few additional tables to capture salary history, employee appraisals, laptop requests, and assigned approvers for salary change requests as shown below.

readme_datamodel.jpg

The sample includes the following APEX components:

Workflows

Employee Appraisal

The Employee Appraisal workflow defines the business process for an employee evaluation. It begins with an employee's filling out a self-evaluation, proceeds to the employee's manager for their additional comments, then ends with a second-level manager's VP review (if one is available). The workflow uses three action tasks explained below: Appraisal - Employee Input, Appraisal - Manager Input, and Appraisal - VP Review.

readme_appraisalworkflow.jpg

Laptop Request

The Laptop Request workflow defines the business process for provisioning an employee with a new laptop. It begins with an approval by a member of the OPERATIONS team, notifying the employee of the outcome of the approval. If rejected, it waits for an appropriate moment before notifying the employee. If approved, it invokes the Laptop Procurement workflow to handle the process of checking stock, optionally ordering a new laptop, and receiving the ordered item before marking the laptop request as delivered. It also returns information about whether the laptop was in stock to the calling workflow. The workflow uses the Laptop Request approval task explained below. and the Laptop Delivered action task explained below.

readme_laptopworkflow.jpg

Laptop Procurement

The Laptop Procurement workflow defines the business process for procuring a new laptop. It begins by checking whether the required laptop type is in stock. If so, it delivers the laptop from that stock and decrements the stock by one. If not, it places an order for the required laptop and waits for a member of the OPERATIONS team to enter delivery date information about the laptop in the Laptop Order Management page once they have received the laptop from the supplier. Once the laptop is delivered, it notifies the employee of the good news. If the invoked workflow returned the information that the laptop was supplied from existing stock, this information triggers an optional additional sentence in the notification email. The email notifications are conditionally sent. They only occur if you have configured the notification email address in the sample's Setup > Email Settings page to set the application setting DEMO_NOTIFICATION_EMAIL. The workflow uses the Laptop Delivered action task explained below.

readme_laptopworkflow.jpg

Approval Task Definitions

  • Job Change

    • contains a task details page URL that points to page 2 ("Task Details")
    • configures its participants at design time,
    • defines one parameter P_NEW_JOB
    • configures a due date that is 2 days from its creation using the interval expression P2D
    • uses a Details Primary Key value related to the EBA_DEMO_APPR_EMP table and has an Actions SQL Query that references additional data about the employee in question using the EMPNO = :APEX$TASK_PK where clause.
    • contains actions related to the Complete event with outcome Approved to:
      • update the JOB column of the appropriate employee in the EBA_DEMO_APPR_EMP table, and
      • conditionally send an email notification when the task is approved
  • Salary Change

    • contains a task details page URL that points to page 15 ("Salary Change Details")
    • determines its participants dynamically at task creation time by invoking the GET_APPROVER_FOR() and GET_ADMIN_FOR() PL/SQL functions in the EBA_DEMO_APPR package
    • defines one parameter P_PROPOSED_SALARY
    • configures a due date that is 7 days from its creation using the interval expression P7D
    • uses a Details Primary Key value related to the EBA_DEMO_APPR_EMP table and has an Actions SQL Query that references additional data about the employee in question using the EMPNO = :APEX$TASK_PK where clause.
    • contains an action related to the Complete event with outcome Approved to perform the following logic when the task is approved:
      • update the SAL column of the appropriate employee in the EBA_DEMO_APPR_EMP table, and
      • insert a row in the EBA_DEMO_APPR_SAL_HISTORY table
  • Bank Account Change

    • contains a task details page URL that points to page 2 ("Task Details")
    • configures its participants at design time, including an Expression type potential owner referencing the task initiator using the bind variable :APEX$TASK_INITIATOR
    • sets the Initiator Can Complete switch to ON to allow the task initiator to approve/reject the task
    • defines one parameter P_NEW_BANK_ACCOUNT
    • uses a Details Primary Key value related to the EBA_DEMO_APPR_EMP table and has an Actions SQL Query that references additional data about the employee in question using the EMPNO = :APEX$TASK_PK where clause.
    • contains actions related to the Complete event with outcome Approved to:
      • update the BANK_ACCOUNT column of the appropriate employee in the EBA_DEMO_APPR_EMP table
  • Laptop Approval

    • contains a task details page URL that (also) points to page 2 ("Task Details")
    • for demo purposes, configures a due date that is 2 minutes from its creation using the scheduler expression expression FREQ=MINUTELY;INTERVAL=2
    • configures an Expiration Policy to automatically renew the task after it has expired (i.e. passed its due date without any action by the task owner) and sets a maximum renewal count to 2 times.
    • determines its participants dynamically at task creation time by invoking the GET_LAPTOP_APPROVER() PL/SQL function in the EBA_DEMO_APPRpackage, passing in the :APEX$TASK_RENEWAL_COUNT bind variable. This allows the function to dynamically assign JANE as the owner if the renewal count is zero (0), STEVE if the renewal count is one (1), and BO if the renewal count is two (2).
    • uses a Details Primary Key value related to the EBA_DEMO_APPR_LAPTOP_REQUESTS table and has an Actions SQL Query that references additional data about the laptop request and the related employee needing that computer by joining EBA_DEMO_APPR_EMP and EBA_DEMO_APPR_LAPTOP_REQUESTS and using the LR.ID = :APEX$TASK_PK where clause.
    • contains actions related to the Before Expire event to:
      • conditionally send an email notification one (1) minute before the task is due to expire as a reminder to the approver

Action Task Definitions

  • Appraisal - Employee Input
    • determines its participants dynamically at task creation time by invoking the GET_APPRAISAL_PARTICIPANT() PL/SQL function in the EBA_DEMO_APPR package, passing in the :APEX$TASK_PK bind variable. This lets the function return the username (i.e. ENAME) of the employee being appraised as the assignee.
    • uses a Details Primary Key value related to the EBA_DEMO_APPR_APPRAISALS table and has an Actions SQL Query that references additional data about the related employee being appraised by joining EBA_DEMO_APPR_EMP and EBA_DEMO_APPR_APPRAISALS and using the A.ID = :APEX$TASK_PK where clause.
  • Appraisal - Manager Input
    • determines its participants dynamically at task creation time by invoking the GET_APPRAISAL_MANAGER() PL/SQL function in the EBA_DEMO_APPR package, passing in the :APEX$TASK_PK bind variable. This lets the function return the username (i.e. ENAME) of the manager of the employee being appraised as the assignee.
    • uses a Details Primary Key value related to the EBA_DEMO_APPR_APPRAISALS table and has an Actions SQL Query that references additional data about the related employee being appraised by joining EBA_DEMO_APPR_EMP and EBA_DEMO_APPR_APPRAISALS and using the A.ID = :APEX$TASK_PK where clause.
  • Appraisal - VP Review
    • illustrates a different technique of determining its participants at task creation time by defining a P_VP_USERNAME parameter, and using the expression :P_VP_USERNAME as the value of the Potential Owner. This allows the workflow to determine the VP username, and pass it in as a parameter when creating the task.
    • uses a Details Primary Key value related to the EBA_DEMO_APPR_APPRAISALS table and has an Actions SQL Query that references additional data about the related employee being appraised by joining EBA_DEMO_APPR_EMP and EBA_DEMO_APPR_APPRAISALS and using the A.ID = :APEX$TASK_PK where clause.
  • Laptop Delivered
    • determines its participants dynamically at task creation time by invoking the GETUSERLIST_FOR_DEPARTMENT() PL/SQL function in the EBA_DEMO_APPR package, passing in the literal'OPERATIONS' department name. This lets the function return a comma-separated list of all the usernames (i.e. ENAME) who belong to the department with the DNAME value of OPERATIONS. These are BO, JANE, STEVE, and PAT.
    • uses a Details Primary Key value related to the EBA_DEMO_APPR_LAPTOP_REQUESTS table and has an Actions SQL Query that references additional data about the related employee being appraised by joining EBA_DEMO_APPR_EMP and EBA_DEMO_APPR_LAPTOP_REQUESTS and using the LR.ID = :APEX$TASK_PK where clause.
    • Involved in illustrating how a task can be completed programmatically using the COMPLETE_TASK() API in the APEX_APPROVAL package.
      • A BEFORE UPDATE FOR EACH ROW database trigger on the EBA_DEMO_APPR_LAPTOP_REQUESTS table conditionally invokes the LAPTOP_DELIVERED() procedure in the EBA_DEMO_APPR package if the value of the DELIVERED_DATE column changes from NULL to NOT NULL.
      • This happens when a member of the OPERATIONS team uses the interactive grid on the Laptop Order Management page to enter in a Delivered Date for a particular laptop request.
      • The LAPTOP_DELIVERED() procedure calls COMPLETE_TASK() to programmatically indicate that the laptop has been delivered so that the APEX workflow engine can proceed to the next activity in the corresponding Laptop Request workflow.

Task Vacation Rule Procedures

The sample application configures a Task Vacation Rule Procedure at application level eba_demo_appr.approval_vacation_handler. This procedure uses the contents of the eba_demo_appr_vacation table to dynamically add additional task potential owners if appropriate to the task instance being created or delegated. It uses the value of the TEMPORARY_BUSINESS_ADMIN application setting to optionally add an additional business administrator to any task instance. The sample's Appraisal - VP Review task definition defines a Task Vacation Rule Procedure at task definition level eba_demo_appr.appraisal_vp_review_handler. This procedure uses the value of the EMP_APPRAISAL_EXTRA_VP_REVIEWERS application setting to add one or more additional potential owners for the action task of giving the final review of an employee's appraisal process.

Pages

  • Home
    • Provides an overview of the workflow, approvals, and tasks features
  • More Information
    • This page
  • Employees
    • Lets users initiate a salary or job change for an employee, or request a new laptop. If the current employee has subordinates (i.e. employees who report directly or indirectly to them as a manager), then the user can also initiate an employee appraisal.
  • Request Salary Change
    • Accepts new proposed salary and creates a new instance of the Salary Change approval task using the Human Task - Create process
  • Request Job Change
    • Accepts the new proposed job and creates a new instance of the Job Change approval task using the Human Task - Create process
  • Request Bank Account Change
    • Accepts the new proposed bank account and creates a new instance of the Bank Account Change approval task using the Human Task - Create process
  • Request Laptop
    • Accepts the laptop type and need by date, inserts the new row into the EBA_DEMO_APPR_LAPTOP_REQUESTS table, and starts a new instance of the Laptop Request workflow, passing in the Details Primary Key value of the newly-created row.
  • Request Employee Appraisal
    • Accepts the appraisal date, inserts the new row into the EBA_DEMO_APPR_APPRAISALS table, and starts a new instance of the Employee Appraisal workflow, passing in the Details Primary Key value of the newly-created row.
  • Task Details [Generated via Create Task Details Page button]
    • Supports participant conversations about an approval in progress, shows history of the approval process, and allows approving, rejecting, or delegating a task. Used for Job Change and Laptop Approval approval tasks in this sample.
  • Salary Change Details [Generated via Create Task Details Page button, then customized]
    • Customized to include graph of employee salary history and percentage change in salary. This illustrates how task definitions need only capture the absolute essential information specific to the task (e.g. P_NEW_SALARY) and can easily query and join with any system of record tables using the task's DETAIL_PK value to present application-specific details of relevance to the task approver. Supports participant conversations about an approval in progress, shows history of the approval process, and allows approving, rejecting, or delegating a task.
  • My Tasks [Generated using Create Page wizard]
    • Shows current user approval tasks awaiting their approval and action tasks awaiting their action.
  • My Requests [Generated using Create Page wizard]
    • Shows current user job-change, salary-change, or laptop requests they initiated.
  • Task Administration [Generated using Create Page wizard]
    • Shows business admins tasks they can administer and allows them to do it if appropriate.
  • Pending Approvals
    • Useful for demo purposes as it shows any open, unassigned or assigned approval tasks and from whom the task is awaiting approval
    • Uses the APEX_TASKS and APEX_APPL_TASKDEFS views in its SQL query to retrieve information about the pending tasks including the DETAILS_LINK_TARGET page for the task, and calls the details_task_url() function in the eba_demo_appr package to substitute the &APP_ID. and &TASK_ID. parameters in that URL.
    • Uses the TASK_TYPE_CODE to filter the results to only show approval tasks.
  • Pending Actions
    • Useful for demo purposes as it shows any open, unassigned or assigned action tasks and from whom the task is awaiting an action
    • Uses the TASK_TYPE_CODE to filter the results to only show action tasks.
  • Setup - shows a list of setup activities, including:
    • Approvers - manage dynamic Salary Change participants optionally based on job code and/or minimum salary
      • Test Approver Assignment - test dynamic Salary Change participant assignment
    • Manage Laptop Stock - set levels of MAC and WIN laptops in stock for use in laptop procurement.
    • Email Settings - Configure an email address user preference for Job Change task's email notification
    • Manage Sample Data - Reset the sample data back to its original state
    • Theme Style Selection - Change the application's UI theme
  • Help
    • Explains how to request and approve salary changes, job changes, and laptops, as well as how managers can initiate an employee appraisal.
  • Workflow Status [Generated using Create Page wizard]
    • Shows current user the workflows in which they are a participant.
    • In this sample, that will be employees in the OPERATIONS department (BO, JANE, STEVE, and PAT)
    • User PAT is also able to administer the workflow instances.
  • Workflow Detail [Generated using Create Page wizard]
    • Shows current user the activity history of a specific workflow
    • In this sample, that will be employees in the OPERATIONS department (BO, JANE, STEVE, and PAT)
    • User PAT is also able to administer the workflow instances.
  • Workflow Dashboard [Generated using Create Page wizard]
    • Shows current user a graphical overview and details about Workflows by State, Active Workload, Fault Workload, and Performance
    • In this sample, that will be employees in the OPERATIONS department (BO, JANE, STEVE, and PAT)
  • Workflow Diagram
    • Shows current user a visual diagram that illustrates the current status of a workflow instance and helps an end-user understand what particular path of activities have already been completed and if applicable, what activity the workflow instance is currently waiting on.
    • In this sample, that will be employees in the OPERATIONS department (BO, JANE, STEVE, and PAT)
  • Workflow Debug Messages
    • Lets users of the OPERATIONS team (BO, JANE, STEVE, and PAT) see recent ten workflow-related debug messages from the APEX_DEBUG_MESSAGES view, ordered by most recently occurred timestamp.
  • Appraisal History
    • Shows the history of employee appraisals for the current user
    • If the current user is a manager, lets them flip a switch to see appraisal history of their subordinates.
  • Employee Self-Review Details
    • Conditionally renders an appropriate form allowing:
      • employee to enter self-evaluation,
      • manager to see employees comments and enter their own about the employee
      • second-level manager (VP) to review both employee and manager comments.
  • Laptop Order Management
    • Lets members of the OPERATIONS team (BO, JANE, STEVE, and PAT) see recently approved laptop requests so they can proceed to complete the order and delivery process by entering the order date and delivery date in the interactive grid.
    • Also provides a switch to see all laptop requests (since by default only ones with no order and delivery date appear in the grid).
  • Manage Vacation Rules
    • Lets Operations Team members edit the vacation rules that affect future task assignments, configure additional employee appraisal VP reviewers, and indicate a temporary business admininstrator for all approvals and action tasks.
  • Sample Login
    • Shows a management hierarchy of employees and simplifies logging into the sample as any of the employees using a for-demo-purposes-only custom authentication scheme.
    • For simplicity, the sample uses a custom authentication scheme so you can easily login as any employee in the fictitious company and quickly switch from one user to another.
    • This lets developers studying APEX workflow, approvals, and task focus on these new features instead of on creating a number of new user accounts in their APEX instance to try out the functionality.
    • Of course, your real-world application will require each user to authenticate with their own password to access the system.
    • The workflow, approvals, and tasks functionality works the same way, regardless of the authentication scheme in use.

Email Template

  • Job Change Notification used by the Job Change task when sending an email notification

Supporting Objects

The sample's supporting object's script creates the EBA_DEMO_APPR_EMP, EBA_DEMO_APPR_DEPT, EBA_DEMO_APPR_SAL_HISTORY, EBA_DEMO_APPR_LAPTOP_REQUESTS, EBA_DEMO_APPR_APPRAISALS, EBA_DEMO_APPR_VACATION and EBA_DEMO_APPR_APPROVERS tables as well as the EBA_DEMO_APPR package containing application-specific PL/SQL code and the EBA_DEMO_APPR_DATA package for installing the sample data. It also contains a deinstallation script that will drop these tables and packages if you delete the application and check the Deinstall Supporting Objects checkbox. Any task instances created by the sample app are deleted when the sample application is deinstalled.

Overview

This section explains how use the sample.

Initiating a Task for an Employee

To request the change of an employee's salary, job, bank account, provision an employee a new laptop, or request an appraisal for a subordinate, login as some employee and then navigate to the Employees page. A cards region displays all the employees with a select list at the top allowing you to sort the list by Name, Job, or Salary. Click the (Edit Salary), (Edit Job), (Bank) or (Laptop) buttons to perform the respective action. If the current user is a manager, then an (Appraisal) button will appear on employee cards for their subordinates.

  • In the Request Job Change modal dialog, enter the new proposed job and click Submit.
  • In the Request Salary Change modal dialog, enter the new proposed salary and click Submit
  • In the Request Bank Account Change modal dialog, enter the new proposed bank account and click Submit
  • In the Request Laptop modal dialog, choose a laptop type, enter a Need By date, and click Submit
  • In the Request Appraisal modal dialog, choose an appraisal due date, and click Submit

readme_employees

Once there is a pending request for salary change, job change, bank account change, new laptop, or appraisal for a specific employee, the related request button is no longer shown for the employee involved until the request is completed.

readme_employees2

Navigating to the Pending Approvals page, you can see any open, unassigned or assigned approval tasks and optionally click on their subject to review the task details. If the task is assigned, the Status column shows "Assigned to USER". If the task is unassigned, it shows the two or more potential approvers like this "Unassigned (USER1, USER2)". This page queries information from the combination of the APEX_TASKS and APEX_TASK_PARTICIPANTS views. Using the information about the approver and admins shown in this page, you know which user to login as to be able to approve or administer the tasks using the appropriate unified task list page.

Causing and Fixing a Fault in the Appraisal Workflow

By design, the sample causes a fault to happen if user KING requests an appraisal for one of her direct reports (BLAKE, BO, CLARK, or JONES). The appraisal process will first wait for the employee to do their self-appraisal, then will wait for KING to add the manager's comments. When the "Determine VP" activity is invoked, it will raise an exception because KING's direct reports have no second-level manager. It does this for demo purposes so you can experience what a faulted workflow looks like. Logging in as PAT the workflow administrator, and visiting the "Workflow Status" page, you can examine the faulted workflow, expand the "Variables" section, and edit the "VP Username" variable value to enter the case-sensitive name of another valid employee (e.g. WARD), then click the (Retry) button to have the workflow engine retry that activity to use the manually-entered employee as the assignee of the VP-level review. Alternatively, you can enter NONE (in capital letters!) and click (Retry) to cause the workflow to skip the VP-level review. If you enter an invalid employee name (or forget to enter the name in CAPITAL LETTERS), a different fault will occur when you click (Retry).

Which Users Can Approve or Administer Tasks?

This section helps you understand which users can approve the Job Change and Salary Change tasks in the sample.

Job Change Task Approvers and Admins

The Job Change task definition configures its task participants at design time as follows:

  • Approvers: BO, JANE, STEVE
  • Admins: PAT

Note that in the APEX Task Definition page approvers are called Potential Owners in the Participants section, and admins are called Business Administrators.

Bank Account Change Task Approvers and Admins

The Bank Account Change task definition configures its task participants at design time as follows:

  • Approvers: BO, JANE, STEVE, (Expression: :APEX$TASK_INITIATOR)
  • Admins: PAT

Note that in the APEX Task Definition page approvers are called Potential Owners in the Participants section, and admins are called Business Administrators. This task definition configures the Initiator Can Complete switch to ON so that the task initiator is also allowed to approve the task.

Salary Change Task Approvers and Admins

The Salary Change task definition configures its task participants dynamically by calling a PL/SQL package function, passing in bind variables representing the primary key of the application data row related to the task (:APEX$TASK_PK), the employee's current job (:JOB), and the task parameter representing the proposed new salary (:P_NEW_SALARY):

  • Approvers: eba_demo_appr.get_approver_for('SALARY_CHANGE', :APEX$TASK_PK, :JOB, :P_NEW_SALARY)
  • Admins: eba_demo_appr.get_admin_for('SALARY_CHANGE', :APEX$TASK_PK, :JOB, :P_NEW_SALARY)

Note that the :JOB bind variable is referencing information from the task definition's Action SQL Query that allows any task to retrieve any relevant data required to process the task participant assignment and/or task actions. The Salary Change task definition configures the following Action SQL Query the includes the JOB column, among others. These Action SQL Query columns can also be referenced as substitution variables using the &JOB. syntax in the task subject, task email template parameter values, and other task-related property values.

  • select ename, sal, initcap(ename) as initcap_ename, job from eba_demo_appr_emp where empno = :APEX$TASK_PK

The get_approver_for() and get_admin_for() functions return one or more user names in a comma-separated string depending on the rows you have configured in the EBA_DEMO_APPR_APPROVERS table. See the Configuring Salary Change Approvers section below for more information on how to do that and how the dynamic approver and admin assignment works.

Approving a Task

As noted above, STEVE is one of three users configured as an approver for a Job Change task. So, if you logout and login to the sample application as user JANE and visit the My Tasks page, you'll see any pending tasks awaiting his attention:

readme_approvals

Notice the task is unassigned because there were multiple available approvers. The task will appear in each of their unified task lists until one of them approves or rejects the task, or else claims ownership of it while they are considering the requested change. STEVE can directly click Approve or Reject from this task list, or click on the task subject line to open the Task Details page where he can add comments, review the task history, and claim ownership of the task.

Task Actions On Approval

The Salary Change task definition configures an action to fire on the task's Complete event, when the outcome is APPROVED. The action executes a single SQL UPDATE statement that changes the SAL column on the appropriate EBA_DEMO_APPR_EMP table row to the new value proposed by the current task (stored during the life of the task in the P_NEW_SALARY parameter).

  • update eba_demo_appr_emp set sal = :P_NEW_SALARY where empno = :APEX$TASK_PK;

The Job Change task definition configures two actions to fire on the task's Complete event, when the outcome is APPROVED. The first action in sequence order executes a single SQL UPDATE statement that changes the JOB column on the appropriate EBA_DEMO_APPR_EMP table row to the new value proposed by the current task (stored during the life of the task in the P_NEW_JOB parameter).

  • update eba_demo_appr_emp set job = :P_NEW_JOB where empno = :APEX$TASK_PK;

The second action in the task definition sends a notification email based on the Job Notification Change email template about the approved change. The email notification is sent only if the application item DEMO_NOTIFICATION_EMAIL is not null. This item's value is computed from an application setting of the same name that is configured using the Administration > Email Settings page in the sample. This illustrates not only the ability to send template-based email notification, but also how task actions can be conditional based on evaluating a server side condition.

Configuring Salary Change Approvers

The Setup > Salary Change Approvers page in the sample allows you to see and change the rows in the EBA_DEMO_APPR_APPROVERS table used by the eba_demo_appr.get_approver_for() and eba_demo_appr.get_admin_for() functions that the Salary Change task definition uses to dynamically determine the approvers and admins at task creation time. The task participants are computed each time a Salary Change task instance is created and can be queried using the combination of the APEX_TASK and APEX_TASK_PARTICIPANTS views. The About this page box at the top of the page explains the approach used by the application business logic to determine which usernames to return. The interactive grid below allows you to edit the contents of the approver table's information.

readme_salapprovers

After clicking Save to make any changes you've made to the approvers table permanent, you can click the Test Salary Approver Assignment... button to test the assignment rules. For example, requesting a salary change to 5500 for an employee like BLAKE whose job is MANAGER will result in having approvers BO or STEVE and an admin user PAT. The user STEVE is included because the job code of MANAGER is one of the codes (and happens to be the only one) in STEVE's Job Codes column and the proposed salary is over the 3000 value in his Minimum Salary column. The user BO is included because MANAGER is one of the codes in BO's Job Codes column. Despite having MANAGER in her list of Job Codes, the user JANE is not included because JANE is the current user and company policy imposes that the same user cannot approve a request that she herself requested. So the business logic excludes the task initiator from the list of approvers.

If you experiment with the data in the Salary Change Approvers page, and do so in a way that produces no matching Admin or no matching Approver for a salary change, then you'll see an appropriate error message explaining that either admin or approver could not be assigned. A similar error will be displayed from the Request Salary Change page on clicking Submit if you have left the salary approver data in this state.

One solution to this situation is to return to the Setup > Salary Change Approvers page and add/edit the rows to ensure there is at least one Admin and at least one Approver defined. Another solution is to use the Administration > Manage Sample Data page to reset the sample data back to its original state.

Completing Approved Laptop Orders

After a laptop request has been approved, the Laptop Request workflow invokes the Laptop Procurement workflow to handle the laptop procurement. If a laptop of the appropriate type is already in stock in house, it is delivered immediately and the stock is decremented. If there is no stock on hand, the Laptop Procurement workfow places an order for the laptop with the supplier and waits for a confirmation that the laptop has been delivered before notifying the employee by email. The delivery confirmation happens as a result of the OPERATIONS team (BO, JANE, STEVE, or PAT) visiting the Laptop Order Management page and entering an Ordered Date and Delivered Date. A database trigger on the EBA_DEMO_APPR_LAPTOP_REQUESTS calls the LAPTOP_DELIVERED() procedure in the EBA_DEMO_APPR package when the DELIVERED_DATE changes from NULL to NOT NULL. This procedure in turn calls the COMPLETE_TASK() procedure in the APEX_APPROVAL package to programmatically mark the appropriate Laptop Delivered action task as completed. This allows the Laptop Request workflow to proceed to the next activity to notify the employee by email if the demo notification Email has been configured in Setup > Email Settings in the sample.

readme_laptopordermgmt

Completing an Employee Appraisal

After a manager has requested an employee appraisal for one of their subordinates, the Employee Appraisal workflow creates an action task for the employee in question to first perform a self-appraisal. When that employee logs in, they'll find a task waiting for them in their My Tasks page. Clicking on the "Your Appraisal - please complete your self review" task, the employee sees the self review form to fill in as shown below:

readme_selfeval

After the employee clicks (Complete) on this action task, the Employee Appraisal workflow creates an action task for the employee's manager to add their additional comments. When their manager logs in, again the manager finds the task to Evaluate the employee. Clicking on the task the same Employee Self-Review Details opens to let the manager see their subordinate's self-evaluation comments and enter their own.

After the manager clicks (Complete) on this action task, the Employee Appraisal workflow creates an action task for the employee's manager's manager (VP-level) to review both sets of evaluation comments. Once the VP completes the review, the Employee Appraisal workflow concludes and the appraisal is visible in the Appraisal History page.

Managing Vacation Rules

Login as a member of the Operations Team (STEVE, PAT, BO, or JANE) to see the Manage Vacation Rules page in the navigation menu. Use this page to configure vacation rules to influence which additional potential owners will be added to a new approval task instance of one or more approval task tasks you can specific in the For Which Approvals? column. If you leave the For Vacationing column username set to the default <Any User> then the Covering User will be added to any approval for any potential owner. Otherwise, you can configure that a covering user be substituting just one particular potential owner, optionally only between a start date and an end date. On the same page, you can use the Additional Appraisal VP Reviews shuttle to add one or more additional potential owners to the final step of the employee appraisal process. Using the Temporary Business Admin list you can configure a user to be added as the business administrator of all approval and action tasks while PAT the default business administrator is on vacation.