Previous  Next          Contents  Index  Glossary  Library

Standard API for PL/SQL Procedures Called by Function Activities

All PL/SQL stored procedures that are called by function activities in an Oracle Workflow process should follow a standard API format. You should also use this API when you define any custom PL/SQL stored procedures for your workflow processes so that the Workflow Engine can properly execute your activity.

The example in 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> ( itemtype in varchar2,
        itemkey in varchar2,
        actid in number,
        funcmode in varchar2,
        result out varchar2 ) is
2-> <local declarations>
3-> begin        
  if ( funcmode = 'RUN' ) then    
  <your RUN executable statements>
  resultout := 'COMPLETE:<result>';
  return;
  endif;
4-> if ( funcmode = 'CANCEL' ) then    
  <your CANCEL executable statements>    
  resultout := 'COMPLETE';    
  return;      
  end if;        
5-> if ( funcmode = '<other funcmode>' ) then    
  resultout := ' ';
  return;
  endif;
6-> exception    
  when others then    
  WF_CORE.CONTEXT ('<package name>', '<procedure name>', <itemtype>, <itemkey>,
  to_char(<actid>), <funcmode>);
  raise;    
7-> end <procedure name>;    

1-> When the Workflow Engine calls a stored procedure for a function activity, it passes four parameters to the procedure and may expect a result when the procedure completes. The parameters are defined here:

itemtypeThe internal name for the item type. Item types are defined in the Oracle Workflow Builder.
itemkey A string that represents a primary key generated by the workflow-enabled application for the item type. The string uniquely identifies the item within an item type.
actid The ID number of the activity that this procedure is called from.
funcmode The execution mode of the function activity. Either 'RUN', 'CANCEL', or 'TIMEOUT'. Other execution modes may be added in the future.
result If a result type is specified in the Activities properties page for the activity in the Oracle Workflow Builder, this parameter represents the expected result that is returned when the procedure completes. The possible results are:
COMPLETE:<result_code>--activity completes with the indicated result code. The result code must match one of the result codes specified in the result type of the function activity.
WAITING --activity is set to wait a specified period of time before it completes. A background engine continually checks for when the activity wait period completes, at which point it processes the activity as complete.
DEFERRED:< date>--activity is deferred to a background engine for execution until a given date. <date> must be of the format: to_char(<date_string>, wf_engine.date_format)
NOTIFIED:< notification_id>:<assigned_user>-- an external entity is notified that an action must be performed. A notification ID and an assigned user can optionally be returned with this result. Note that the external entity must call CompleteActivity( ) to inform the Workflow engine when the action completes.
ERROR:< error_code>--activity encounters an error and returns the indicated error code.
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 run if the value of funcmode is 'RUN'. One of the executable statements can return a result for the procedure. For example, a result can be 'COMPLETE:APPROVED'.

4-> This section clears the activity and can contain executable statements that run if the value of funcmode is 'CANCEL'. Often times, this section contains no executable statements to simply return a null value, but this section also provides you with the chance to 'undo' something if necessary. An activity can have a funcmode of 'CANCEL' in these special cases:

5->This section handles execution modes other than 'RUN' or 'CANCEL'. Currently 'TIMEOUT' is the only other execution mode available, but others may be added in the future. Since your activity does not need to implement any of these other possible modes, it should simply return null.

6->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.


         Previous  Next          Contents  Index  Glossary  Library