You are on page 1of 4

User Hook Summary

tamkamal@hotmail.com Last update 24 Oct. 2012
1

Overview
API User Hooks allow users to extend the business logic of the standard business rules that are
executed by APIs. This is done by allowing custom procedures to be called at specific points in
the standard APIs. For instance, a user may want to implement User Hooks for one of the
following reasons:
 To extend the validation of data beyond what the standard system provides.
 To maintain data held in extra customer specific tables (not part of Oracle Applications)
as it is entered.
 To send alerts when particular events happen within Oracle Human Resources
Management System (HRMS)


Advantages
User Hooks allow extra business logic to be inserted in exactly the right place in the application
without needing to bespoke any of the standard APIs. Upgrades are no problem as the hooks will
be regenerated during the upgrade process. However, Oracle reserves the right to change the HR
schema at any time, which may necessitate modifications to customized PL/SQL procedures.
The main advantages of hooks over custom library are that they only need to be implemented in
one place whereas custom library modifications could conceivably have to be made on several
clients. They are also immediately available to any interface that calls the API. For example,
Forms, Self Service, Data Pump, etc.


Disadvantages
A customized procedure called by a User Hook will only work if the API that the call has been
added to is executed. It sounds obvious. However, at the time of writing there are still a large
number of forms that don't call APIs. The Enter Person Information form is one of them.
Therefore, any hook added to the Create_Employee API will not be executed from this form. It is
policy to eventually convert all existing forms to call APIs but this will not be a short term
process. Unfortunately, there is no list available which indicates which forms call APIs and which
do not. The only certainty is that all new forms will call APIs. A sensible approach to any
implementation of configuration logic, therefore, if required to be executed by a standard form, is
for the user to use a hook if the form calls a supported API, and custom library if not.


User Hook Summary


tamkamal@hotmail.com Last update 24 Oct. 2012
2

Steps to Implementing User Hooks
1- Use this SQL statement to get original procure which you will use
SELECT AHM.API_MODULE_ID,
AHM.API_MODULE_TYPE,
AHM.MODULE_NAME,
AHK.API_HOOK_ID,
AHC.API_HOOK_CALL_ID,
AHK.HOOK_PACKAGE,
AHK.HOOK_PROCEDURE,
AHC.SEQUENCE,
AHC.CALL_PACKAGE,
AHC.CALL_PROCEDURE,
AHC.STATUS,
AHC.API_HOOK_CALL_ID,
AHC.OBJECT_VERSION_NUMBER
FROM HR_API_HOOKS AHK, HR_API_MODULES AHM,
HR_API_HOOK_CALLS AHC
WHERE AHM.MODULE_NAME LIKE '%PERSON_EXTRA_INFO%'
-- AHM.MODULE_NAME LIKE '%CREATE_SIT%'
-- AHM.MODULE_NAME LIKE '%CREATE_PERSON_ABSENCE%'
AND AHM.API_MODULE_TYPE = 'BP' -- Before
-- AND AHK.API_HOOK_TYPE = 'AP' -- After
AND AHK.HOOK_PACKAGE LIKE '%BK1'
AND AHK.API_MODULE_ID(+) = AHM.API_MODULE_ID
AND AHC.API_HOOK_ID(+) = AHK.API_HOOK_ID
-- AND AHC.SEQUENCE > 2000
ORDER BY 7, 5 ASC
Change only Module name to get what you need

2- Choose which API_HOOK_CALL_ID is lowest.
3- Choose HOOK_PACKAGE name and get your procedure from it.
4- Make new package and put this procedure in it.
5- Make your conditions as business requirements.
6- To get error message you can use one of these methods:
Method 1:
IF NAT <> 'QA' THEN
IF userenv('LANG') = 'AR' THEN
dbms_standard.raise_application_error(num => -20999 ,msg => 'اذه ضزقلا فظوملل يزطقلا طقف');
END IF;
dbms_standard.raise_application_error(num => -20999,msg => 'Nationality must be Qatari');
END IF;
Num => any number above 20000

User Hook Summary


tamkamal@hotmail.com Last update 24 Oct. 2012
3

Method 2: Use Application Messages
[R] System Administrator > System Administration > Messages

IF p_absence_days > 5 THEN
FND_MESSAGE.CLEAR;
FND_MESSAGE.SET_NAME('PER', 'PER_999967232_ABS_MOURNING');
IF USERENV('LANG') = 'AR' THEN
fnd_message.set_token ('VAC', 'ةساجإ ءاشعلا ةجردلل ىلولا');
ELSE
fnd_message.set_token ('VAC', 'First Class Mourning Vacation');
END IF;
fnd_message.set_token ('DAY', '5');
fnd_message.raise_error;
END IF;

SELECT MAX(MESSAGE_NUMBER)
FROM FND_NEW_MESSAGES
Parameter to use
it in procedure
User Hook Summary


tamkamal@hotmail.com Last update 24 Oct. 2012
4

7- Register your procedure
DECLARE
obj number := 1; -- any number from starting from 1
l_api_hook_call_id number :=503; -- Original API hook call id
p_api_hook_id number := 3839; -- Original API hook id
BEGIN
hr_api_hook_call_api.create_api_hook_call
(p_validate => false,
p_effective_date => sysdate,
p_api_hook_id => p_api_hook_id, -- Original API hook id
p_api_hook_call_type => 'PP',-- (package procedure) this is the only available type now.
p_sequence => 2001, -- any number above 2000 and it is used to sequence the execution of the
validation procs
p_enabled_flag => 'Y',
p_call_package => 'Package Name', -- your package name
p_call_procedure => 'Procedure Name', -- your procedure name
p_api_hook_call_id => l_api_hook_call_id, -- Original API hook call id
p_object_version_number => obj); -- any number from starting from 1
COMMIT;
END;

8- Run first select statement and be sure that your new record had inserted and the status is N
9- Logon to the application server (by telnet … open server_name …. User name/passwd)
10- Run:
cd $PER_TOP/admin/sql 11i
Or
cd $PER_TOP/patch/115/sql R12
Then
sqlplus apps/apps DB username/DB password
11- Run a script called “hrahkone” on the server
SQL> @hrahkone
12- Write API_MODULE_ID for your new record
>>>>> To delete a registration:
hr_api_hook_call_api.delete_api_hook_call (p_validate, p_api_hook_call_id,
p_object_version_number)