Sie sind auf Seite 1von 5

PLSQL Procedures for Oracle Workflow

All PL/SQL stored procedures that are called by function or notification activities in an Oracle Workflow
process should follow this standard API format so that the Workflow n!ine can properly e"ecute the
activity#
procedure <procedure name> $ itemtype in varchar%&
itemkey in varchar%&
actid in number&
funcmode in varchar%&
resultout out varchar% ' is
% (local declarations)
* be!in
if $ funcmode + ,-./, ' then
(your RUN executable statements)
resultout 0+ ,1O2PL30(result),4
return4
endif4
5 if $ funcmode + ,1A/1L, ' then
<your CANCEL executable statements>
resultout 0+ ,1O2PL3,4
return4
end if4
6 if $ funcmode + ,-SPO/7, ' then
(your RESPOND executable statements)
resultout 0+ ,1O2PL3,4
return4
endif4
8 if $ funcmode + ,9O-WA-7, ' then
<your OR!ARD executable statements>
resultout 0+ ,1O2PL3,4
return4
end if4
: if $ funcmode + ,3-A/S9-, ' then
(your "RANSER executable statements)
resultout 0+ ,1O2PL3,4
return4
endif4
; if $ funcmode + ,3I2O.3, ' then
<your "#$EOU" executable statements>
resultout 0+ ,1O2PL3,4
return4
end if4
< if $ funcmode + ,(ot%er &uncmode), ' then
resultout 0+ , ,4
return4
endif4
=> e"ception
when others then
W9?1O-#1O/3@3 $,(pac'a(e name),& ,(procedure name),& (itemtype)&
(item'ey)&
to?char$(actid>'& (&uncmode)'4
raise4
== end <procedure name>4
When the Workflow n!ine calls a stored procedure for a function activity& it passes four parameters to the
procedure and may e"pect a result when the procedure completes# 3he parameters are defined here0
Itemtype : 3he internal name for the item type# Item types are defined in the Oracle Workflow Auilder#
Itemkey : A strin! that represents a primary key !enerated by the workflowBenabled application
for the item type# 3he strin! uniCuely identifies the item within an item type#
ACTID 03he I7 number of the activity that this procedure is called from#
Funcmode 03he e"ecution mode of the activity# If the activity is a function activity& the mode is
either RUN or CANCEL. If the activity is a notification activity& with a
postBnotification function& then the mode can be ,RESPOND,& ,FORWARD,& ,TRANSFER,&
or ,TIMEOUT,# Other e"ecution modes may be added in the future#
If a result type is specified in the Activities properties pa!e for the
activity in the Oracle Workflow Auilder& this parameter represents the
e"pected result that is returned when the procedure completes# 3he
possible results are0
COMPLETE:<result_code>Dactivity completes with the indicated
result code# 3he result code must match one of the result codes
specified in the result type of the function activity#
WAITINGDactivity is pendin!& waitin! on another activity to
complete before it completes# An e"ample is the Standard ,A/7,
activity#
DEFERRED:<date>Dactivity is deferred to a back!round en!ine for
e"ecution until a !iven date# <date> must be of the format0
to_char(<date_string>, wf_engine.date_format)
NOTIFIED:<notification_id>:<assigned_user>D
an e"ternal entity is notified that an action must be performed# A
notification I7 and an assi!ned user can optionally be returned with
this result# /ote that the e"ternal entity must call CompleteActi)ity$ '
to inform the Workflow en!ine when the action completes#
ERROR:<error_code>Dactivity encounters an error and returns the
indicated error code#
%3his section declares any local ar!uments that are used within the procedure#
*3he procedure body be!ins in this section with an IF statement# 3his section contains one or more
e"ecutable statements that run if the value of funcmode is RUN# One of the e"ecutable statements can
return a result for the procedure# 9or e"ample& a result can be ,1O2PL30APP-OE7,#
53his section clears the activity and can contain e"ecutable statements that run if the value of funcmode
is CANCEL# Often times& this section contains no e"ecutable statements to simply return a null value&
but this section also provides you with the chance to ,undo, somethin! if necessary#
63his section is needed only for postBnotification functions# .se this section to include e"ecution
statements that run if the value of funcmode is ,RESPOND,& that is& when a -SPO/7 operation is
performed# 9or e"ample& include e"ecution statements that validate the response of the notification#
83his section is needed only for postBnotification functions# .se this section to include e"ecution
statements that run if the value of funcmode is ,FORWARD,& that is& when a notification,s state chan!es to
,9O-WA-7,# 9or e"ample& include e"ecution statements that validate the role to which the notification is
bein! forwarded#
:3his section is needed only for postBnotification functions# .se this section to include e"ecution
statements that run if the value of funcmode is ,TRANSFER,& that is& when a notification,s state chan!es to
,3-A/S9-,#
;3his section should only be used for postBnotification functions associated with Eotin! activities# .se
this section to include e"ecution statements that run if a Eotin! activity times out# 9or e"ample& if the
votin! activity times out before all recipients respond& you can include lo!ic that completes the activity and
determines how to interpret the responses based on the current response pool# 9or nonBEotin! activities
that time out& you should model any subseCuent behavior in your process dia!ram usin! a (3imeout)
transition to another activity#
<3his section handles e"ecution modes other than RUN, CANCEL, ,RESPOND,& ,FORWARD,&
,TRANSFER,& or ,TIMEOUT,.Other e"ecution modes 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#
=>3his section calls W9?1O-#1O/3@3$ ' if an e"ception occurs& so that you can include conte"t
information in the error stack to help you locate the source of an error#
Stnd!d API "o! n Item Type Se#ecto! o! C##$ck Funct%on
9or any !iven item type& you can define a sin!le function that operates as both a selector and a callback
function# A selector function is a PL/SQL procedure that automatically identifies the specific process
definition to e"ecute when a workflow is initiated for a particular item type but no process name is
provided# Oracle Workflow also supports usin! a callback function to reset or test item type conte"t
information# Fou can define one PL/SQL procedure that includes both selector and callback functionality
by followin! a standard API#
Oracle Workflow can call the selector/callback function with the followin! commands0
-./Dto select the appropriate process to start when either of the followin! two conditions occur0
B A process is not e"plicitly passed to
W9?/GI/#1reateProcess#
B A process is implicitly started by
W9?/GI/#1ompleteActivity with no prior call to
W9?/GI/#1reateProcess#
S3?13@Dto establish any conte"t information that a function activity in an item type needs to e"ecute&
before a new database session be!ins#
3S3?13@Dto determine if the current item type conte"t information is correct before e"ecutin! a
function# 9or e"ample& the selector/callback function in 3S3?13@ mode lets you check if a form can be
launched with the current conte"t information Hust before the /otification 7etails web pa!e launches a
reference form# If the conte"t is incorrect& the form cannot be launched and a messa!e is displayed to that
effect#
= procedure <procedure name> $ item?type in varchar%&
item?key in varchar%&
activity?id in number&
command in varchar%&
resultout in out varchar%' is
% (local declarations)
* be!in
if $ command + ,-./, ' then
(your RUN executable statements)
resultout 0+ ,(Name o& process to run),4
return4
endif4
5 if $ command + ,S3?13@, ' then
<your executable statements &or establis%in( context in&ormation>
return4
end if4
6 if $ command + ,3S3?13@, ' then
(your executable statements &or testin( t%e )alidity o& t%e current context in&ormation)
resultout 0+ ,<"RUE or ALSE> ,4
return4
endif4
8 if $ command + ,(ot%er command), ' then
resultout 0+ , ,4
return4
endif4
: e"ception
when others then
W9?1O-#1O/3@3 $,(pac'a(e name),& ,(procedure name),& (itemtype)&
(item'ey)&
to?char$(actid>'& (command)'4
raise4
; end <procedure name>4
Workflow n!ine