Thursday, October 28, 2010

User Hooks

Oracle has provided some space for user customization with user hook, it is a predefined structure where you can add you logic according to your business need.In some of public APIs (Mailny in ASO APIs like  ASO_QUOTE_PUB) we have option for it.

There are two type of user hooks :
Pre-processing Hooks: it will execute your custom logic before the API does any actual processing.
In the APIs where there is an option for user hooks you can see this code for pre-processing hooks :
IF (JTF_USR_HKS.ok_to_execute(G_PKG_NAME, l_api_name, 'B', 'C')) THEN
<CALL TO PRE-HOOK> -- Example UPDATE_QUOTE_PRE
<ERROR HANDLING>
END IF;
Here B stands for BEFORE and C for Custom Hooks.

Post-processing Hooks:  it will execute your custom logic after the API did all processing.
For Post hooks you will find :
IF (JTF_USR_HKS.ok_to_execute(G_PKG_NAME, l_api_name, 'A', 'C')) THEN
<CALL TO POST-HOOK>  -- Example UPDATE_QUOTE_POST
<ERROR HANDLING>
END IF;

A stands for AFTER and C for Custom Hooks.

***Note : If you see 'V' instead of 'C', that means it is the space for 'Vertical' hooks. These hooks should not be enabled or disabled by customer and the state must be left unchanged.

Package specification and body are already defined for user hooks, do not touch specification, just add your custom logic in the body and compile the package body.

After successful compilation the user hook body you need to enable your hook to be effective.

UPDATE JTF_USER_HOOKS
        SET EXECUTE_FLAG = 'Y'
 WHERE upper(PKG_NAME) = upper('&ENTER_PACKAGE_NAME')
      AND upper(API_NAME) = upper('&ENTER_API_NAME')
      AND PROCESSING_TYPE = '&ENTER_PROC_TYPE' 
   -- A for POST , B for PRE
     AND USER_HOOK_TYPE = 'C';  
   -- Don't use 'V' here, have already mentioned above.

For disabling use the same script with EXECUTE_FLG = 'N'

Hope it will help to some extent to understand user hooks :)
Feel frre to post your query if you have any doubt.


Reference :  Melalink DocID=373923.1

3 comments:

  1. A very good sample example of user hook is also presnt in th ebelow link

    https://oracleappsatechniciansview.blogspot.in

    ReplyDelete
  2. Hello Friends, I am trying to to register a user hook and try to capture deleted SIT details into a custom table..Unfortunately my User hook is not registering for some reason. Kindly someone guide me.
    DECLARE
    L_API_HOOK_ID NUMBER := 3858; L_API_HOOK_CALL_ID NUMBER; L_OBJECT_VERSION_NUMBER NUMBER; L_SEQUENCE NUMBER;
    BEGIN
    SELECT APPS.HR_API_HOOKS_S.NEXTVAL INTO L_SEQUENCE FROM DUAL;
    APPS.HR_API_HOOK_CALL_API.CREATE_API_HOOK_CALL ( P_VALIDATE => FALSE,
    P_EFFECTIVE_DATE => TO_DATE ('01-JAN-1901', 'DD-MON-YYYY'), P_API_HOOK_ID => L_API_HOOK_ID,
    P_API_HOOK_CALL_TYPE => 'PP', P_SEQUENCE => L_SEQUENCE, P_ENABLED_FLAG => 'Y', P_CALL_PACKAGE => 'perc_sit_del_uh_pkg',
    P_CALL_PROCEDURE => 'delete_sit_b', P_API_HOOK_CALL_ID => L_API_HOOK_CALL_ID, P_OBJECT_VERSION_NUMBER => L_OBJECT_VERSION_NUMBER);
    DBMS_OUTPUT.PUT_LINE ('L_API_HOOK_CALL_ID ' || L_API_HOOK_CALL_ID);
    EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('Error in seeding user hook procedures: '|| SQLERRM); COMMIT; END;
    --to register user hook
    declare l_api_module_id number := 1761; begin apps.hr_api_user_hooks_utility.create_hooks_one_module (l_api_module_id);
    dbms_output.put_line('Success'); exception when others then dbms_output.put_line('Exception : '||SQLERRM); commit; end;
    --to delete user hook
    SELECT api_hook_call_id, object_version_number INTO ln_api_hook_call_id,ln_object_version_number FROM hr_api_hook_calls WHERE call_package = 'perc_sit_del_uh_pkg' AND call_procedure = 'delete_sit_b';
    ---------------

    ReplyDelete
  3. CREATE OR REPLACE PACKAGE PERC.perc_sit_del_uh_pkg AS procedure delete_sit_b( p_person_analysis_id in number ,p_pea_object_version_number in number);
    end perc_sit_del_uh_pkg;
    ----------------
    CREATE OR REPLACE PACKAGE BODY PERC.perc_sit_del_uh_pkg AS
    PROCEDURE delete_sit_b (p_person_analysis_id IN NUMBER, p_pea_object_version_number IN NUMBER) IS
    l_employee_number VARCHAR2 (99); l_person_analysis_id NUMBER; l_segment2 VARCHAR2 (99); l_segment6 VARCHAR2 (99);
    BEGIN
    SELECT papf.employee_number, ppa.person_analysis_id, pac.segment2, pac.segment6 INTO l_employee_number, l_person_analysis_id, l_segment2,
    l_segment6
    FROM per_person_analyses ppa, per_analysis_criteria pac, per_all_people_f papf, hr_lookups HL
    WHERE ppa.analysis_criteria_id = pac.analysis_criteria_id AND papf.person_id = ppa.person_id AND EFFECTIVE_END_DATE = hr_general.end_of_time
    AND pac.id_flex_num = 50248 --LANGUAGE
    -- and papf.employee_number = 'BO690'
    AND HL.LOOKUP_CODE = pac.segment2 AND HL.ENABLED_FLAG = 'Y' AND ppa.person_analysis_id = p_person_analysis_id AND HL.LOOKUP_TYPE = 'PERC_LANGUAGES';
    INSERT INTO PERC.PERC_ITM_SIT_UH_CAPTURE (person_analysis_id, object_version_number, segment2, segment14,
    creation_date,
    last_update_date)
    VALUES (l_person_analysis_id, l_employee_number, l_segment2, l_segment6, SYSDATE, SYSDATE - 1);
    COMMIT; EXCEPTION WHEN NO_DATA_FOUND THEN INSERT INTO PERC.PERC_ITM_SIT_UH_CAPTURE (person_analysis_id,
    object_version_number, segment2, segment14, creation_date, last_update_date)
    VALUES (l_person_analysis_id, l_employee_number, l_segment2, l_segment6, SYSDATE, SYSDATE - 1);
    WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE ('Error in seeding deleted data: ' || SQLERRM);
    END delete_sit_b;
    END perc_sit_del_uh_pkg;

    ReplyDelete