You are on page 1of 3

User Hooks

Oracle has provided user hooks to implement custom logic or validation on standard processes.
1.
2.
3.

For example:
Creating a element entry when creating an absence
validating the DFF segments in Absence before creating a absence.
Validation on creating EITs, Element entries, absence, termination of employee etc
Custom hook package (User Hook package) is a custom package where we write procedures
for doing the customizations. The user hook procedure should have same parameters as
standard API module procedure which invokes the user hook.
Now lets go through the steps to attach a user hook. I am assuming the user hook for create
absence after process.
Step 1 :
Get the Module id from table HR_API_MODULES. In my case the module name is
like 'CREATE%ABSENCE%'. Hence I query for the module using the below query.
SELECT*FROMhr_api_modulesWHEREmodule_nameLIKE'CREATE%ABSENCE%';

I get the api_module_id as 1731.


--------------------------------------------------------------------------Step 2:
Next I query for hook id in table hr_api_hooks for after process. Note that 'AP' means After
Process hook and 'BP' isBefore Process hook.
SELECT*FROMhr_api_hooksWHEREapi_module_id=1731;

I get the api_hook_id as 3840


-------------------------------------------------------------------------Step 3:
If you know the Module name , hook package name and hook procedure , you can use the script
below .
Script for attaching the hook:
setserveroutputonsize1000000
DECLARE

ln_api_hook_call_idnumber;
ln_object_version_numbernumber;
ln_api_hook_idnumber;

BEGIN

selectahk.api_hook_id
intoln_api_hook_id
fromhr_api_hooksahk,hr_api_modulesahm
whereahm.module_name='CREATE_PERSON_ABSENCE'
andahm.api_module_type='BP'
andahk.hook_package='HR_PERSON_ABSENCE_BK1'
andahk.hook_procedure='CREATE_PERSON_ABSENCE_A'
andahk.api_hook_type='AP'AfterProcess
andahk.api_module_id=ahm.api_module_id;

insertarowintoHR_API_HOOK_CALLS

hr_api_hook_call_api.create_api_hook_call
(p_effective_date=>to_date('14MAR2014','DDMONYYYY')
,p_api_hook_id=>ln_api_hook_id
,p_api_hook_call_type=>'PP'
,p_sequence=>3029
,p_enabled_flag=>'Y'
,p_call_package=>'XXMUD_DISCIPLINARY_ACTION_PKG'Custom
HookPKG
,p_call_procedure=>'CREATE_UNAUTHORIZED_ABS_ENTRY'Procedure
forcreatingentries
,p_api_hook_call_id=>ln_api_hook_call_id
,p_object_version_number=>ln_object_version_number);

DBMS_OUTPUT.PUT_LINE('RegisteredHOOK...'||ln_api_hook_call_id);

EXCEPTION
WHENOTHERSTHEN
DBMS_OUTPUT.PUT_LINE(SUBSTR('Error:'||SQLERRM,1,255));
END;

Step 4:
Next step is to run the pre-processor to the hook. Without running the pre-processor the user hook
will not work.
DECLARE
l_module_idNUMBER;Passthemoduleid
BEGIN
hr_api_user_hooks_utility.create_hooks_one_module(1282);
END;

COMMIT;

Step 5:
Next step is to verify if hook is registered.
SELECT*FROMhr_api_hook_calls
WHEREcall_package='XXMUD_DISCIPLINARY_ACTION_PKG';

If STATUS column is 'V' (Stands for Valid) and ENABLED_FLAG = 'Y' then you have successfully registered the
user hook.
---------------------------------------------------------------------------Deleting User Hook:
DECLARE
ln_object_version_numberNUMBER;
ln_api_hook_call_idNUMBER;
BEGIN
Gettheapi_hook_call_idandobject_version_number
SELECTapi_hook_call_id,object_version_number
INTOln_api_hook_call_id,ln_object_version_number
FROMhr_api_hook_calls
WHEREhook_call_package='XXMUD_DISCIPLINARY_ACTION_PKG'
ANDhook_procedure='CREATE_UNAUTHORIZED_ABS_ENTRY';
APItodeletetheuserhook
hr_api_hook_call_api.delete_api_hook_call
(p_api_hook_call_id=>ln_api_hook_call_id,
API_HOOK_CALL_ID
p_object_version_number=>ln_object_version_number);
Object_version_number
DBMS_OUTPUT.PUT_LINE('DELETEDHOOK...');

EXCEPTION
WHENOTHERSTHEN
DBMS_OUTPUT.PUT_LINE(SUBSTR('Error:'||SQLERRM,1,255));
END;