Overview

Previous blog post Interaction Between Workflow Engine and Business Event System – Part 1 described declarative methods using Workflow Standard activities for interaction between Workflow Engine and Business Event System. These are the simplest methods but they are not the only methods. Interaction between the Workflow Engine and Business Event System is also possible using API calls within function activity or subscription rule function implementations.

Workflow Engine Calling Business Event System APIs

There are public APIs available in WF_EVENT package, the most straightforward of which is the WF_EVENT.Raise() API that simply raises a specific event. The figure below shows a workflow process that raises an event using the WF_EVENT.Raise API called within a function activity. This EVT_TEST_PKG.Event_Call() API is listed in the Sample APIs section.

This works exactly like the standard EVENT activity with Raise option. The flexibility of using an API within function activity implementation is that it may perform many other tasks before and/or after raising an event including raising other events.

Business Event System Calling Workflow Engine APIs

An event subscription could also call on APIs under the WF_ENGINE package such as WF_ENGINE.Event() to pass along the event information to a workflow process. The figure below shows such an custom event subscription.

The referenced EVT_TEST_PKG.Event_Rule() API is listed in the Sample APIs section.

Sample APIs

The APIs mentioned above are contained in a hypothetical package listed below.

create or replace package body EVT_TEST_PKG as

procedure Event_Call(itemtype  in            varchar2,
                     itemkey   in            varchar2,
                     actid     in            varchar2,
                     funcmode  in            varchar2,
                     resultout in out nocopy varchar2)
is

  l_cnt        number;
  l_seq        number;
  l_parameters wf_parameter_list_t := wf_parameter_list_t();

begin

  if (funcmode <> wf_engine.eng_run) then
    resultout := wf_engine.eng_null;
    return;
  end if;

  select count(*)
    into l_cnt from user_sequences
    where sequence_name = 'EVT_TEST_SEQ';

  if (l_cnt < 1) then
    execute immediate 'create sequence EVT_TEST_SEQ nocache';
  end if;

  execute immediate 'select EVT_TEST_SEQ.nextval from dual' into l_seq;

  wf_event.raise(p_event_name => 'oracle.apps.wf.mailer.unsolicited',
                 p_event_key  => 'unsolicited_test_' || l_seq,
                 p_event_data => NULL,
                 p_parameters => l_parameters,
                 p_send_date  => sysdate);

  resultout :=  wf_engine.eng_completed || ':' || wf_engine.eng_null;

exception

  when others then
    Wf_Core.Context('EVT_TEST_PKG', 'Event_Call',
                    itemtype,  itemkey, to_char(actid), funcmode);
    raise;

end Event_Call;

function Event_Rule(p_subscription_guid in     raw,
                    p_event             in out nocopy wf_event_t)
  return varchar2
is

  l_wftype   varchar2(30);
  l_wfname   varchar2(30);
  l_ikey     varchar2(240);
  lparamlist wf_parameter_list_t;

begin

  select wf_process_type, wf_process_name
    into   l_wftype, l_wfname
    from   wf_event_subscriptions
    where  guid = p_subscription_guid;

  lparamlist := p_event.Parameter_List;
  wf_event.AddParameterToList('SUB_GUID', p_subscription_guid,lparamlist);
  p_event.Parameter_List := lparamlist;

  l_ikey := nvl(p_event.Correlation_ID, p_event.Event_Key);

  wf_engine.Event(itemtype      => l_wftype,
                  itemkey       => l_ikey,
                  process_name  => l_wfname,
                  event_message => p_event);

  return 'SUCCESS';

exception

  when others then
    Wf_Core.Context('EVT_TEST_PKG', 'Event_Rule',
                    p_event.getEventName(), p_subscription_guid);
    wf_event.setErrorInfo(p_event, 'ERROR');
    return 'ERROR';

end Event_Rule;

end EVT_TEST_PKG;
/

show errors;
commit;
exit;

Additional Resources

For more information on the Workflow Engine, Business Event Systems, and Workflow Builder refer to below documents.

  1. Oracle Workflow Administrator’s Guide
  2. Oracle Workflow Developer’s Guide