Friday, October 1, 2010

Basics of Business events

HI All,
some basics syntax and statements to work with business events..

Business Events:
Business event is an activity in the system which is of some significance .Like creating a purchase order, booking a sales order or ship confirming one.

Subscription:

A subscription is action that needs to be performed on occurrence of the business event



What are the standard parameters for the procedure to be subscribed to business events?The custom plsql code should be a packaged function.
It will have two default parameters
1. P_susbcription_guid raw data type
2. P_event the event data

FUNCTION xx_test
( p_subscription_guid IN RAW , p_event IN OUT NOCOPY wf_event_t) RETURN VARCHAR2


How to get the Event Data if the data type is Rule or message? l_event_name := p_event.getEventName();
l_event_key := p_event.getEventKey();

How to get the parameters defined along with the business event?
l_parameter_list WF_PARAMETER_LIST_T ;

l_parameter_list:=p_event.getParameterList();

IF l_parameter_list IS NOT NULL THEN

FOR i IN l_parameter_list.FIRST .. l_parameter_list.LAST
LOOP

INSERT INTO XX_PARAM_NAME_VALUES
VALUES(l_parameter_list(i).getName() , l_parameter_list(i).getValue());

END LOOP;

ELSE
Dbms_output.put_line(‘No parameters’);
END IF;

How to get a value of a parameter?
p_event.getparameter(parametername)
p_event is the value passed to the procedure from the subscription.

How to raise a custom Business Event?
wf_event.raise( p_event_name => '',
p_event_key => '',
p_event_data => l_eventdata,
p_parameters => l_parameter_list);


Event data need to be populated only when the subscription requires message data
l_message := wf_event.test('');

This above function will provide whether any of the subscription requires business event data or not
if l_message = 'KEY' then
-- Raise the Event
wf_event.raise( p_event_name => ,
p_event_key => ,
p_parameters => l_parameter_list);
else
if l_message = 'MESSAGE' then
if l_xmldocument is not null then
dbms_lob.createtemporary(l_eventdata, FALSE,
DBMS_LOB.CALL);
dbms_lob.write(l_eventdata, length(l_xmldocument), 1 ,
l_xmldocument);
-- Raise the Event with the message
wf_event.raise( p_event_name => '',
p_event_key => '',
p_event_data => l_eventdata,
p_parameters => l_parameter_list);
else
-- Raise the Event without the message
wf_event.raise( p_event_name => '',
p_event_key => '',
p_parameters => l_parameter_list);
end if;


end if;


How to add parameters to the business event while raising a business event?procedure AddParameterToList
(p_name in varchar2,
p_value in varchar2,
p_parameterlist in out wf_parameter_list_t);
wf_event.addparametertolist(p_name=>’userid’,p_valehue=>’100’,p_parameterlist=>l_parameter_list);
use the above statement before wf_Event.raise