business event

Upload: divakarnath07

Post on 11-Oct-2015

41 views

Category:

Documents


0 download

TRANSCRIPT

ContentsIntroduction1Create Business Event1Create Business Event Subscription3Raising the Business Event8Tracking Launched Business Events8Error Subscriptions for Business Event11Business Event Groups13Appendix A: Bouncing Agent Listeners15Appendix B: Workflow Administrator Privilege16

IntroductionOracle Business Event is an excellent tool that has been backbone of Oracle Workflow since Oracle E-Business Suite version 11.5.8 and has become absolute necessity since then. Versatility of the Business Events is not limited only to Workflow or PLSQL; Business Events can be called from Java too. Today, Business events are used to integrate to Fusion Middleware Technologies such as SOA, BAM, BI, etc. Business events are typically a one-way, fire-and-forget, asynchronous way to announce a business occurrence. Within E-business Suite, they offer an excellent way to implement in-flow-customizations. Typically, instead of writing heavy logic in the Triggers on standard tables, we can fire these light weight business events from triggers, and achieve much better performance. We can also fire it from Forms Personalization by calling a Backend Procedure. This document will talk about how to create Business Event, Subscription and how to Test it. Please find two Appendixes for troubleshooting.Create Business EventSelect Workflow Administrator Web Applications responsibility. Select Business Event function.

We will create a new Business Event

If you do not see the Create Event or Create Event Group button, refer to Appendix B to get the privilege.Create a custom event by giving Name in the pattern oracle.apps...Ensure that Owner Name and Owner Tag represent a licensed product.

Sample Business Event is as follows:

Create Business Event SubscriptionNext step is to create a subscription to Business Event. Whenever a business event is raised, all enabled are executed (dictated by Phase). If phase is between 1 and 99, the subscription is called immediately; whereas if it is greater than 99 it is marked as deferred (i.e. it is executed when Workflow Background Process runs with Process Deferred = Y). Query the Business Event Name and Click on the Subscription icon.

We have following options for Action Type

We need to provide details about Action Type in the Next Screen. For Example, if Action Type is Custom, then we need to provide name custom procedure that should be executed. In case of Launch Workflow, we need to specify Name of the Workflow and the Process. In case of Send Notification, we need to specify Message Type, Message Name and the Recipient.

A sample custom subscription is as follows:create or replace FUNCTION xx_business_event_sub ( p_subscription_guid IN RAW, p_event IN OUT NOCOPY wf_event_t)RETURN VARCHAR2 AS

l_parameter_list wf_parameter_list_t := wf_parameter_list_t(); l_event_key VARCHAR2(240); l_event_name VARCHAR2(240); l_parameter_t wf_parameter_t := wf_parameter_t (NULL, NULL); l_parameter_name l_parameter_t.NAME%TYPE; l_param_value l_parameter_t.VALUE%TYPE; i PLS_INTEGER; l_error varchar2(2000); l_po_header_id NUMBER;

BEGIN l_event_name := p_event.geteventname (); l_event_key := p_event.geteventkey (); l_parameter_list := p_event.getparameterlist (); l_po_header_id := p_event.GetValueForParameter('PO_HEADER_ID'); IF l_parameter_list IS NOT NULL THEN FOR i in l_parameter_list.FIRST..l_parameter_list.LAST LOOP l_parameter_name := NULL; l_param_value := NULL;

l_parameter_name := l_parameter_list (i).getname (); l_param_value := l_parameter_list (i).getvalue ();

END LOOP;

END IF; COMMIT; RETURN 'SUCCESS'; EXCEPTION WHEN OTHERS THEN l_error := 'In When Others of Subscription'||substr(sqlerrm,1,1000); wf_core.CONTEXT (pkg_name => 'xx_business_event_sub' , proc_name => 'xx_business_event_sub' , arg1 => p_event.geteventname () , arg2 => p_subscription_guid ); wf_event.seterrorinfo (p_event => p_event, p_type => 'ERROR');

RETURN 'ERROR';END xx_business_event_sub;/Raising the Business Event

First, lets define a sequence for generating event key primary key of an instance of business event.create sequence xx_business_events_s start with 1 increment by 1;Once we have the setup ready, we can test a business event by executing following block: DECLARE l_event_key VARCHAR2 (100); l_err_msg VARCHAR2(4000); l_paramlist_t apps.wf_parameter_list_t; begin SELECT xx_business_events_s.NEXTVAL INTO l_event_key FROM DUAL;

wf_event.addparametertolist ('PO_HEADER_ID', 1000, l_paramlist_t ); wf_event.RAISE ('xxcust.oracle.apps.demo_event', l_event_key, NULL, l_paramlist_t, NULL );END;Ensure to fire Commit after the above block is executed.Tracking Launched Business EventsTo verify the successful launch of Business Event, we can navigate to Workflow Administrator Web Applications >> Oracle Applications Manager >> Workflow Manager

Click on Agent Activity link under Throughput.

Select WF_DEFERRED agent and click Search Agent Entry Details.

Enter Business Event Name and Click Go Button.

Initially, such event has status as Ready. Once the subscription is executed, the status changes to Processed

You can write debug messages in custom subscription to verify that it is indeed executed successfully. Sample objects are as follows:create table xx_business_events_log (id number, event_name VARCHAR2(240), event_key VARCHAR2(100), object_id NUMBER, log_date DATE, log_message VARCHAR2(2000) );

create sequence xx_business_event_logs_s start with 1 increment by 1;

create or replace procedure xx_business_event_debug ( p_event_name IN VARCHAR2, p_event_key IN VARCHAR2, p_object_id IN NUMBER, p_log_message IN VARCHAR2)AS pragma autonomous_transaction;BEGIN INSERT INTO xx_business_events_log (id, event_name, event_key, object_id, log_date, log_message) VALUES (xx_business_event_logs_s.nextval, p_event_name, p_event_key, p_object_id, sysdate, p_log_message); commit;END;

Error Subscriptions for Business EventIt becomes difficult to trace an error if something goes wrong in the event subscription. The Most difficult problem is that there is no way to know if something went wrong (as a subscription runs as part of separate session (deferred mode)). So, as a good practice, we should add an Error Subscription to a business event. Such error subscription is automatically fired if we set up the context of the error correctly in the EXCEPTION block of subscription and return ERROR.Query the Business Event, go to Subscriptions.

Click on the button Create Subscription.

We specify the Source Type as Error for such subscription and specify Rule Data as Key. For the current demonstration, we will send a notification to SYSADMIN about the failure of subscription. We choose action as Launch Workflow as we will be leveraging a Standard Workflow notification. Click Next to specify the workflow details.

During runtime, if any subscription fails, the exception should be caught and ERROR should be returned. System generates a notification to SYSADMIN as follows:

Business Event GroupsIf the definition of Subscriptions is same for multiple business events, we can define a Group of Business Events and attach Subscription to Business Event Group, instead of attaching it to individual events. A group can be created by clicking on Create Event Group button.

Sample Business Event Group is as follows: Events can be added to the Group by clicking Add Events to Group Button.Subscription to a group can be attached exactly the same way.Appendix A: Bouncing Agent ListenersIf we make any change to subscription program, the agents need to be bounced. Click on the Notification Mailers status icon.

Click on Workflow Mailer Service.

Choose Restart All and click Go.

State will change to Restarting. Hit F5 to refresh the status.

Once they are Activated, click on Service Components to go back.

Choose Action as Start to restart the Workflow Notification Mailer.

Appendix B: Workflow Administrator PrivilegeIf you do not have Workflow Administrator Privilege, then you will have to use SYSADMIN user to reset the Workflow System Administrator to your role. You can also assign it to responsibility role such as Workflow Administrator Web Applications so that all the users that have the responsibility assigned will act as a Workflow System Administrator.