Monday, June 17, 2013

Business Event: Creation And Subscription



A business event is an occurrence in an internet/intranet application or program that might be significant to other objects in a system or to external agents.

For instance, the creation of a purchase order is an example of a business event in a purchasing application.

Creating/Defining a Business event 

There must be a unique internal name for a business event.
The suggested format for these internal names is a compound structure of identifiers
separated by periods (.) as follows: (Which is case-sensitive.)

<company>.<family>.<product>.<component>.<object>.<event>

Example : oracle.apps.xxokl.am.test_busi_event

Steps to create a new Business Event:

Navigation à System Administrator à Workflow à Administrator Workflow à Business Event

            à Click on “Create Event”

à Fill all the required field (marked with *)

                Name     should be in the format specified above.
                Status     must be “Enabled”
                Owner Name    Enter program name here.(Any oracle module name)
                Owner Tag        Enter program id here (Oracle module short name)

à Click on “Apply”


à It will give the confirmation of successful event creation
 

Subscription of a Business event


An event subscription is a registration indicating that a particular event is significant to a
particular system and specifying the processing to perform when the triggering event
occurs.

Steps to Subscribe a Business Event:

Navigation à System Administrator à Workflow à Administrator Workflow à Business Event

à Search the business event create above (for which subscription has to be created)

                    à Click on “Subscription”


à Put the required fields in the next window.
Subscriber region,

System (Where the subscription executes) 

Click on the System field’s up arrow icon to display a list of systems from which to choose

 Triggering Event region,

Source Type  (To which the subscription applies) 
• Local - The subscription applies only to events raised on the subscribing system. 
• External - The subscription applies only to events received by an inbound agent on the subscribing system.  

• Error - The subscription applies to only to errored events dequeued from the WF_ERROR queue.

 Event Filter
Name of your business event.

Source Agent (optional -to which the subscription applies). 
The subscription is executed only when the triggering event is received from that agent.  


Note: In most cases, the Source Agent field is left blank.


Execution Condition region,

Phase Number 

It specify the order in which subscriptions that apply to the same event are executed 
Status
Select Enabled or Disabled.
Rule Data. 
• Key - The subscription requires only the event key. 
                                           • Message - The subscription requires the complete event data


Action Type Region

 Action Type

There are total 6 types of ‘Action Types’. Select anyone as your requirement put at least the required fields in ‘Action’ region of the selected ‘Action Type’.

List of the ‘Action Type’ and corresponding ‘Action’ is mentioned below. 
‘ * ‘ mark indicates the required field)



Action Type
Action
Additional Options
Priority (1 required 0 optional)
Custom




Java Rule Function

0

PL/SQL Rule Fuction

0

Workflow Type

0

Workflow Process

0

Out Agent

0

To Agent

0

*Priority

1
Launch Workflow




*Workflow Type

1

*Workflow Process

1

*Priority

1


Add Subscription Parameters




Launch when Parameters Match



Launch when Parameters Match

Receive Message from Trading Partner




*Priority

1
Send To Agent




Out Agent

0

To Agent

0

*Priority

1


Add Subscription Parameters



Launch When Parameters Match

Send Notification




*Message Type

1

*Message Name

1

*Recipient

1

Callback

0

Context

0

Comment

0

Due Date

0

*Priority

1
Send Message to Trading Partner




*Priority

1



















































Note :: All the required fields have LOV attached


 On Error 
     Stop and Rollback 
     Skip to Next  


Subscription Parameters Region 
You can enter any additional parameters for the rule function in the Parameters field. Specify the name and value for each parameter in the following format:



<name1>=<value1> <name2>=<value2> ... <nameN>=<valueN>

 Documentation Region
 Owner name
     Enter program name here.
Owner tag 
     Enter program ID here.
Customization Level 
    Customization level “User” is automatically set for subscriptions that you define. 
Description(optional)

      You can give the description about your subscription/event. 

Warning: Each subscription must have a unique combination of subscribing system,source type, triggering event, source agent, phase, owner name, and owner tag. If you are defining several subscriptions with similar properties, assign each    subscription a different phase number to differentiate it from the others. 


Following Subscription is an example with “Action Type-Custom”




à Click On “Next”



à Click On “Apply”


à It will give the confirmation message of successful subscription
 
Sample Subscribed Function:

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

   l_parmlist                wf_parameter_list_t;
   l_user_id                 number;
   l_resp_id                 number;
   l_application_id          number;

begin
   ---- get the parameter list for the event.
   l_parmlist := p_event.getparameterlist ();
   
   l_user_id := to_number (p_event.getvalueforparameter ('USER_ID'));
         
   l_resp_id := to_number (p_event.getvalueforparameter ('RESP_ID'));
         
   l_application_id := to_number (p_event.getvalueforparameter ('RESP_APPL_ID'));
       
   --<write your business logic>

    return 'SUCCESS';
exception
   when others then
      return 'FAILURE';
end xx_test_event_func;

23 comments:

  1. Hi,

    can you pls explain how a pre attribute change event business subscription event functions.

    I have a pl/sql function which validates an update when the event is triggered so that invalid updates will not be committed to the database.

    But before the validation happens, the changes are getting commited to the database due to validations are not happening properly

    Pls help if you any idea where i'm going wrong

    ReplyDelete
    Replies
    1. Hi,

      What I understood is you are triggering an event on some field update and trying to validate that update before committing the same to the database. update is getting committed because it is happening in different session. Is it a seeded event or custom one. if it is custom one how you are triggering it?
      I am not sure what is your requirement is. There can be many other ways to achieve. If it is a form field you can do it through form personalisation or if it a DFF attach a value set against it.

      Delete
    2. Hi Abhay,

      I want to validate the information before committing to the DB. I am using the seeded "oracle.apps.pos.sdh.ext.preAttributeChange" BE.
      I have written a PLSQL function and calling it from a online subscription. But it doesn't work.

      Regards,
      Rohit

      Delete
    3. Hi Rohit,

      Did you get your issue resolved? As I am experiencing exactly the same problem... How to get the previous data values of the form fields (to allow for validation) before committing to the database.

      Kindly let me know how you resolved yours and if not still confirm please.

      Regards,
      Femi

      Delete
    4. Hi Femi,
      For supplier hub pre BE, it didnt work for me. You can check with Oracle by raising a SR. might be some patch is missing.

      But the pre BE for PDH worked and we were able to find the changed values and the specific attribute.

      Thanks,
      Rohit

      Delete
    5. Thanks Rohit for your quick response.

      Please what do you mean by PDH? And how where you able to find the changed values and specific attributes?

      Kind regards,
      Femi

      Delete
    6. Hi Femi,

      PDH is Oracle Product Data Hub. There are predefined BE for the use of PDH. Triggering was these BE was happening properly and I was able to find out the changed values and specific attributes,

      Thanks,
      Rohit

      Delete
    7. Thank You Rohit for your reply.

      You wouldn't mind sharing a sample code, would you? It is just that I have been searching and looking for any assistance on how to do this.

      My specific requirement is that for BE (oracle.apps.cs.sr.ServiceRequest.updated), I need to get values of some attributes like 'OWNER_id', 'CUSTOMER_ID' and some others which are not listed in the p_event.getparameterlist

      So I would very much appreciated whatever help you can give me.

      Thanks in advance,
      Femi

      Delete
    8. Hello Femi,

      I didn't exactly get your problem, but it seems you are trying to refer to the values of certain additional fields other than the fields passed passed by the BE subscription.

      So you have the specific set of parameters passed by the BE subscription from p_event.getparameterlist. Can you not derive the OWNER_ID and CUSTOMER_ID from the parameters passed by p_event.getparameterlist?

      Thanks,
      Rohit

      Delete
    9. Hi Rohit,

      Thank you for taking the time to read and reply my queries...

      Yes, you are right in that I am trying to refer to the values of certain additional fields other than the fields passed by the BE subscription.

      Derived values from p_event.getparameterlist are giving current values i.e. changed values.

      Where as, for my logic to happen, I need to know if the previous value has changed, if not, do nothing, else perform logic.
      Therefore, I need the previous values before the change is committed to compare it with what is now been stored in d database.

      I hope it is explained better.

      Delete
    10. Hello Femi,

      You are welcome.

      You can do something like this, create a procedure/function and define it as a pragma autonomous_transaction. Derive your additional field values inside that procedure. I think it should give you the old values.

      Please try this approach and do let me know if it works.

      Thanks,
      Rohit

      Delete
    11. Hi Femi,

      Got your email, my apologies for late response.
      As I have mentioned above two operations are being performed in two different sessions so with my little knowledge I am not sure how to get the previous values and validating the same before committing. You can look for other options apart from business event.

      @Rohit, The challenge here to get previous values first.

      Delete
    12. Also, please check if any preAttributeChange or preCommit event available.

      Delete
    13. Hi Abhi, Femi,

      This is something which I implemented... if its an on-line BE subscription call then using pragma autonomous transaction will give you the previous value. I don't have the procedure reference right now, but it works.

      Do give it a try and let me know.

      Thanks,
      Rohit

      Delete
    14. Thank you both for your assistance....

      Yes Rohit, let me apply the pragma autonomous transaction approach and get back to you. Since this will be my first time using it, it might take a bit longer....

      Thanks and regards,
      Femi

      Delete
    15. Hi Rohit,

      This is the steps taken so far:-

      For BE - oracle.apps.cs.sr.ServiceRequest.updated

      Created subscription 1 - add_parameters (PLSQL FUNCTION) - at phase 70
      - This is where I use 'wf_event.AddParameterToList' and have 'PRAGMA autonomous_transaction;'

      Created subscription 2 - perform logic (PLSQL) that's supposed to compare previous and current values of attribute - at Phase 101

      Outcome - error (Event Error Message: 3103: Attribute 'PRV_OWNER_ID' does not exist for item 'oracle.apps.cs.sr.ServiceRequest.updated/11664-1975-EVT'.
      )

      Regards,
      Femi

      Delete
    16. Hey Femi,

      This will not work.

      Follow the below stesp:

      1) Define two additional functions i) get_attr_old_value_f ii) get_attr_value_f (both the sample provided below)
      **************************************************************************
      FUNCTION get_attr_old_value_f(i_param1 IN NUMBER)
      RETURN VARCHAR2
      IS
      l_attr_old_value VARCHAR2(1000);

      PRAGMA AUTONOMOUS_TRANSACTION;
      BEGIN
      --

      RETURN l_attr_old_value;
      EXCEPTION
      WHEN no_data_found THEN
      RETURN '';
      WHEN OTHERS THEN
      -- ERROR PROCESSING
      RETURN '';
      END get_attr_old_value_f;
      **************************************************************************
      FUNCTION get_attr_new_value_f(i_param1 IN NUMBER)
      RETURN VARCHAR2
      IS
      l_attr_new_value VARCHAR2(1000);

      BEGIN
      --

      RETURN l_attr_new_value;
      EXCEPTION
      WHEN no_data_found THEN
      RETURN '';
      WHEN OTHERS THEN
      -- ERROR PROCESSING
      RETURN '';
      END get_attr_old_value_f;
      **************************************************************************


      2) Create a custom subscription 1 - at phase < 100
      This calls a function let say xx_test_event_func (something like mentioned below)

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

      l_parmlist wf_parameter_list_t;
      l_user_id number;
      l_resp_id number;
      l_application_id number;

      l_old_val number;
      l_new_val number;

      begin
      ---- get the parameter list for the event.
      l_parmlist := p_event.getparameterlist ();

      l_user_id := to_number (p_event.getvalueforparameter ('USER_ID'));

      l_resp_id := to_number (p_event.getvalueforparameter ('RESP_ID'));

      l_application_id := to_number (p_event.getvalueforparameter ('RESP_APPL_ID'));

      l_old_val := get_attr_old_value_f (1);
      l_new_val := get_attr_new_value_f (1);

      --


      --
      return 'SUCCESS';
      exception
      when others then
      return 'FAILURE';
      end xx_test_event_func;
      **************************************************************************

      Thanks,
      Rohit

      Delete
    17. Hi Rohit,

      IT WORKED!!!!!!!

      Though, I have not tested to confirm values but at least I am getting different values for 'new' and 'old' attributes.

      The obvious question then is - do I have to create functions for every attributes needed i.e. customer_is, owner_id, owner_group_id, key_worker etc....

      Also noticed that we are not using the concept of AddParameterToList... is this ok?

      Many thanks,
      Femi

      Delete
    18. Hi Femi,
      AddParameterToList is used when you want to raise a BE from backend. Basically you assign the parameters to the wf_parameter_list_t table type variable.

      For deriving the rest of the values, you can think of any design approach you wish to use let say a procedure or function.

      Cheers..!!
      Rohit

      Delete
    19. Hi Rohit,
      Thanks for the suggestions....
      Could you kindly clarify if having the main function (xx_test_event_func) with phase 90 calling another function (get_attr_old_value_f) with 'PRAGMA AUTONOMOUS_TRANSACTION;' (which has a commit) is the reason I am getting error message below:-
      Unable to lock the record. Cause: The record is being modified by another user

      Regards,
      Femi

      Delete
    20. Hi Femi,

      If you are doing a commit on the same table/row then it can give you the error which you are receiving or it can be a oracle bug also.

      You can try to debug though.

      Thanks,
      Rohit

      Delete
  2. Hi Abhay,

    I would like to know how can we raise event ap invoice approval event in R12 .

    I tried to subscribe one simple package for invoice approval event but its not working and do not whether event is firing or not,

    Can you please help in this.

    Thanks,
    Neel

    ReplyDelete
    Replies
    1. Hi Neel,

      Please check the related post 'Business Event - Possible Errors'.

      Regards,
      Abhay

      Delete