Oracle Workflow can call the selector/callback function with the following commands:

RUN--to select the appropriate process to start when either of the following two conditions occur:

A process is not explicitly passed to WF_ENGINE.CreateProcess.

A process is implicitly started by WF_ENGINE.CompleteActivity with no prior call to WF_ENGINE.CreateProcess.

SET_CTX--to establish any context information for an item type and item key combination that a function activity in the item type needs in order to execute. The Workflow Engine calls the selector/callback function with this command each time it encounters a new item type and item key combination, to ensure that the correct context information is always set.

TEST_CTX--to determine if the current item type context information is correct before executing a function. For example, the selector/callback function in TEST_CTX mode lets you check if a form can be launched with the current context information just before the Notification Details web page launches a reference form. If the context is incorrect, the form cannot be launched and a message is displayed to that effect. See: To View the Details of a Notification, Oracle Workflow User's Guide.

The standard API for the selector/callback function is as follows. This section is numbered with the notation 1-> for easy referencing. The numbers and arrows themselves are not part of the procedure.

1-> procedure <procedure name> (item_type in varchar2, item_key in varchar2, activity_id in number, command in varchar2, resultout in out varchar2) is

If the function is called with 'RUN', the name of the process to run must be returned through the resultout parameter. If the function is called with 'SET_CTX', then no return value is expected. If the function is called with 'TEST_CTX', then the code must return 'TRUE' if the context is correct or 'FALSE' if the context is incorrect. If any other value is returned, Oracle Workflow assumes that this command is not implemented by the callback.

2-> This section declares any local arguments that are used within the procedure.

3-> The procedure body begins in this section with an IF statement. This section contains one or more executable statements that make up your selector function. It executes if the value of command is 'RUN'. One of the executable statements should return a result for the procedure that reflects the process to run. For example, a result can be 'REQUISITION_APPROVAL', which is the name of a process activity.

4-> This section contains one or more executable statements that set item type context information if the value of command is 'SET_CTX'. The Workflow Engine calls the selector/callback function with this command each time it encounters a new item type and item key combination, before executing any function activities for that combination. This command is useful when you need to set item type context information in a database session before the activities in that session can execute as intended. For example, you might need to set up the responsibility and organization context for function activities that are sensitive to multi-organization data.

5-> This section contains one or more executable statements that validate item type context information if the value of command is 'TEST_CTX'. The Workflow Engine calls the selector/callback function with this command to validate that the current database session context is acceptable before the Workflow Engine executes an activity. For example, this callback functionality executes when the Notification Details web page is just about to launch a reference form. The code in this section should return 'TRUE' if the context is correct, and 'FALSE' if the context is incorrect. If the context is incorrect, you can raise an exception and place a message in the WF_CORE error system to indicate the reason the context is invalid. The raised exception is also printed in an error message in the form.

6-> This section handles execution modes other than 'RUN', 'SET_CTX' or 'TEST_CTX' as others may be added in the future. Since your function does not need to implement any of these other possible commands, it should simply return null.

7-> This section calls WF_CORE.CONTEXT( ) if an exception occurs, so that you can include context information in the error stack to help you locate the source of an error. See: CONTEXT, Oracle Workflow API Reference.