User Hooks in Oracle Apps for comments validation


I had a requirement to Validate the comments for certain leave types. So I first try to do the same in BG_ABSENCE_DURATION Fast formula. However I was facing some problem that is

  • Not able to capture comments or Absence Attendance Id in fast formula
  • While clicking on next only the record will get created and comments will be passed still it was complex to write logic in FF

So I went with User Hooks.

In simple words user hooks is functionality provided in Oracle HRMS for validating or extending our custom functionality based on business rules.

What we can do with user hooks is : Validate EIT, SIT, Absence and manipulate and maintain the data for Oracle to our tables

Attention: You should not manually edit the API source code files supplied by Oracle If you do modify these codes, Oracle Applications will be unable to support the product, and upgrades may not be possible. Oracle Applications only supports direct calls to the published APIs. Direct calls to any other server-side package procedures or functions that are written as part of the Oracle HRMS Applications suite are not supported.

Note: All Oracle HRMS forms does not use HRMS APIs, User hook can be implemented for only those forms which perform functions through API. The HR_API_HOOKS table holds all available API hooks for APIs in HR_API_MODULES table.

Implementation Steps For User Hooks

Four steps are required to implement API User Hooks:

Step 1 – Identifying the correct User Hook API

SELECT ahk.api_hook_id,
ahk.api_module_id,
ahk.hook_package,
ahk.hook_procedure
FROM hr_api_hooks ahk, hr_api_modules ahm
WHERE ahm.module_name like ‘%_PERSON_ABSENCE%’
AND ahm.api_module_type = ‘BP’
AND ahk.api_hook_type = ‘AP’
AND ahk.api_module_id = ahm.api_module_id

It will show all Person Absence relevant APIs.We need to select the correct API that matched with our requirement. For Example for above mentioned requirement, we shall select CREATE_PERSON_ABSENCE_A API. We shall note its API_HOOK_ID (3840) and API_MODULE_ID (1731) as API_HOOK_ID will be used at the time of registration of user hook mentioned in Step 3 ahead and API_MODULE_ID will be needed in running the processor in Step 4.

Step 2. Create PL/SQL procedure to execute your logic.

CREATE OR REPLACE PACKAGE APPS.XXHW_ABS_USERHOOK_PKG
AS
PROCEDURE XXHW_CREATE_ABS_VAL_P
(P_EFFECTIVE_DATE in DATE
,P_PERSON_ID in NUMBER
,P_BUSINESS_GROUP_ID in NUMBER
,P_ABSENCE_ATTENDANCE_TYPE_ID in NUMBER
,P_ABS_ATTENDANCE_REASON_ID in NUMBER
,P_COMMENTS in LONG
,P_DATE_NOTIFICATION in DATE
,P_DATE_PROJECTED_START in DATE
,P_TIME_PROJECTED_START in VARCHAR2
,P_DATE_PROJECTED_END in DATE
,P_TIME_PROJECTED_END in VARCHAR2
,P_DATE_START in DATE
,P_TIME_START in VARCHAR2
,P_DATE_END in DATE
,P_TIME_END in VARCHAR2
,P_ABSENCE_DAYS in NUMBER
,P_ABSENCE_HOURS in NUMBER
,P_AUTHORISING_PERSON_ID in NUMBER
,P_REPLACEMENT_PERSON_ID in NUMBER
,P_ATTRIBUTE_CATEGORY in VARCHAR2
,P_ATTRIBUTE1 in VARCHAR2
,P_ATTRIBUTE2 in VARCHAR2
,P_ATTRIBUTE3 in VARCHAR2
,P_ATTRIBUTE4 in VARCHAR2
,P_ATTRIBUTE5 in VARCHAR2
,P_ATTRIBUTE6 in VARCHAR2
,P_ATTRIBUTE7 in VARCHAR2
,P_ATTRIBUTE8 in VARCHAR2
,P_ATTRIBUTE9 in VARCHAR2
,P_ATTRIBUTE10 in VARCHAR2
,P_ATTRIBUTE11 in VARCHAR2
,P_ATTRIBUTE12 in VARCHAR2
,P_ATTRIBUTE13 in VARCHAR2
,P_ATTRIBUTE14 in VARCHAR2
,P_ATTRIBUTE15 in VARCHAR2
,P_ATTRIBUTE16 in VARCHAR2
,P_ATTRIBUTE17 in VARCHAR2
,P_ATTRIBUTE18 in VARCHAR2
,P_ATTRIBUTE19 in VARCHAR2
,P_ATTRIBUTE20 in VARCHAR2
,P_OCCURRENCE in NUMBER
,P_PERIOD_OF_INCAPACITY_ID in NUMBER
,P_SSP1_ISSUED in VARCHAR2
,P_MATERNITY_ID in NUMBER
,P_SICKNESS_START_DATE in DATE
,P_SICKNESS_END_DATE in DATE
,P_PREGNANCY_RELATED_ILLNESS in VARCHAR2
,P_REASON_FOR_NOTIFICATION_DELA in VARCHAR2
,P_ACCEPT_LATE_NOTIFICATION_FLA in VARCHAR2
,P_LINKED_ABSENCE_ID in NUMBER
,P_BATCH_ID in NUMBER
,P_CREATE_ELEMENT_ENTRY in BOOLEAN
,P_ABS_INFORMATION_CATEGORY in VARCHAR2
,P_ABS_INFORMATION1 in VARCHAR2
,P_ABS_INFORMATION2 in VARCHAR2
,P_ABS_INFORMATION3 in VARCHAR2
,P_ABS_INFORMATION4 in VARCHAR2
,P_ABS_INFORMATION5 in VARCHAR2
,P_ABS_INFORMATION6 in VARCHAR2
,P_ABS_INFORMATION7 in VARCHAR2
,P_ABS_INFORMATION8 in VARCHAR2
,P_ABS_INFORMATION9 in VARCHAR2
,P_ABS_INFORMATION10 in VARCHAR2
,P_ABS_INFORMATION11 in VARCHAR2
,P_ABS_INFORMATION12 in VARCHAR2
,P_ABS_INFORMATION13 in VARCHAR2
,P_ABS_INFORMATION14 in VARCHAR2
,P_ABS_INFORMATION15 in VARCHAR2
,P_ABS_INFORMATION16 in VARCHAR2
,P_ABS_INFORMATION17 in VARCHAR2
,P_ABS_INFORMATION18 in VARCHAR2
,P_ABS_INFORMATION19 in VARCHAR2
,P_ABS_INFORMATION20 in VARCHAR2
,P_ABS_INFORMATION21 in VARCHAR2
,P_ABS_INFORMATION22 in VARCHAR2
,P_ABS_INFORMATION23 in VARCHAR2
,P_ABS_INFORMATION24 in VARCHAR2
,P_ABS_INFORMATION25 in VARCHAR2
,P_ABS_INFORMATION26 in VARCHAR2
,P_ABS_INFORMATION27 in VARCHAR2
,P_ABS_INFORMATION28 in VARCHAR2
,P_ABS_INFORMATION29 in VARCHAR2
,P_ABS_INFORMATION30 in VARCHAR2
,P_ABSENCE_ATTENDANCE_ID in NUMBER
,P_OBJECT_VERSION_NUMBER in NUMBER
);
END XXHW_ABS_USERHOOK_PKG;

 

CREATE OR REPLACE PACKAGE BODY APPS.XXHW_ABS_USERHOOK_PKG
IS
PROCEDURE XXHW_CREATE_ABS_VAL_P (
P_EFFECTIVE_DATE IN DATE,
P_PERSON_ID IN NUMBER,
P_BUSINESS_GROUP_ID IN NUMBER,
P_ABSENCE_ATTENDANCE_TYPE_ID IN NUMBER,
P_ABS_ATTENDANCE_REASON_ID IN NUMBER,
P_COMMENTS IN LONG,
P_DATE_NOTIFICATION IN DATE,
P_DATE_PROJECTED_START IN DATE,
P_TIME_PROJECTED_START IN VARCHAR2,
P_DATE_PROJECTED_END IN DATE,
P_TIME_PROJECTED_END IN VARCHAR2,
P_DATE_START IN DATE,
P_TIME_START IN VARCHAR2,
P_DATE_END IN DATE,
P_TIME_END IN VARCHAR2,
P_ABSENCE_DAYS IN NUMBER,
P_ABSENCE_HOURS IN NUMBER,
P_AUTHORISING_PERSON_ID IN NUMBER,
P_REPLACEMENT_PERSON_ID IN NUMBER,
P_ATTRIBUTE_CATEGORY IN VARCHAR2,
P_ATTRIBUTE1 IN VARCHAR2,
P_ATTRIBUTE2 IN VARCHAR2,
P_ATTRIBUTE3 IN VARCHAR2,
P_ATTRIBUTE4 IN VARCHAR2,
P_ATTRIBUTE5 IN VARCHAR2,
P_ATTRIBUTE6 IN VARCHAR2,
P_ATTRIBUTE7 IN VARCHAR2,
P_ATTRIBUTE8 IN VARCHAR2,
P_ATTRIBUTE9 IN VARCHAR2,
P_ATTRIBUTE10 IN VARCHAR2,
P_ATTRIBUTE11 IN VARCHAR2,
P_ATTRIBUTE12 IN VARCHAR2,
P_ATTRIBUTE13 IN VARCHAR2,
P_ATTRIBUTE14 IN VARCHAR2,
P_ATTRIBUTE15 IN VARCHAR2,
P_ATTRIBUTE16 IN VARCHAR2,
P_ATTRIBUTE17 IN VARCHAR2,
P_ATTRIBUTE18 IN VARCHAR2,
P_ATTRIBUTE19 IN VARCHAR2,
P_ATTRIBUTE20 IN VARCHAR2,
P_OCCURRENCE IN NUMBER,
P_PERIOD_OF_INCAPACITY_ID IN NUMBER,
P_SSP1_ISSUED IN VARCHAR2,
P_MATERNITY_ID IN NUMBER,
P_SICKNESS_START_DATE IN DATE,
P_SICKNESS_END_DATE IN DATE,
P_PREGNANCY_RELATED_ILLNESS IN VARCHAR2,
P_REASON_FOR_NOTIFICATION_DELA IN VARCHAR2,
P_ACCEPT_LATE_NOTIFICATION_FLA IN VARCHAR2,
P_LINKED_ABSENCE_ID IN NUMBER,
P_BATCH_ID IN NUMBER,
P_CREATE_ELEMENT_ENTRY IN BOOLEAN,
P_ABS_INFORMATION_CATEGORY IN VARCHAR2,
P_ABS_INFORMATION1 IN VARCHAR2,
P_ABS_INFORMATION2 IN VARCHAR2,
P_ABS_INFORMATION3 IN VARCHAR2,
P_ABS_INFORMATION4 IN VARCHAR2,
P_ABS_INFORMATION5 IN VARCHAR2,
P_ABS_INFORMATION6 IN VARCHAR2,
P_ABS_INFORMATION7 IN VARCHAR2,
P_ABS_INFORMATION8 IN VARCHAR2,
P_ABS_INFORMATION9 IN VARCHAR2,
P_ABS_INFORMATION10 IN VARCHAR2,
P_ABS_INFORMATION11 IN VARCHAR2,
P_ABS_INFORMATION12 IN VARCHAR2,
P_ABS_INFORMATION13 IN VARCHAR2,
P_ABS_INFORMATION14 IN VARCHAR2,
P_ABS_INFORMATION15 IN VARCHAR2,
P_ABS_INFORMATION16 IN VARCHAR2,
P_ABS_INFORMATION17 IN VARCHAR2,
P_ABS_INFORMATION18 IN VARCHAR2,
P_ABS_INFORMATION19 IN VARCHAR2,
P_ABS_INFORMATION20 IN VARCHAR2,
P_ABS_INFORMATION21 IN VARCHAR2,
P_ABS_INFORMATION22 IN VARCHAR2,
P_ABS_INFORMATION23 IN VARCHAR2,
P_ABS_INFORMATION24 IN VARCHAR2,
P_ABS_INFORMATION25 IN VARCHAR2,
P_ABS_INFORMATION26 IN VARCHAR2,
P_ABS_INFORMATION27 IN VARCHAR2,
P_ABS_INFORMATION28 IN VARCHAR2,
P_ABS_INFORMATION29 IN VARCHAR2,
P_ABS_INFORMATION30 IN VARCHAR2,
P_ABSENCE_ATTENDANCE_ID IN NUMBER,
P_OBJECT_VERSION_NUMBER IN NUMBER)
IS
L_ABSENCE_TYPE VARCHAR2 (500) := NULL;
L_ASSIGNMENT_ID NUMBER;
L_ABSENCE_START_DATE DATE
:= NVL (P_DATE_START, P_DATE_PROJECTED_START);
L_ABSENCE_END_DATE DATE := NVL (P_DATE_END, P_DATE_PROJECTED_END);
L_ABSENCE_FUTURE_ST_DATE DATE;
L_ABSENCE_FUTURE_END_DATE DATE;
LN_LENGTH NUMBER := 0;
LC_MSG VARCHAR2 (500);
BEGIN
IF P_ABSENCE_ATTENDANCE_TYPE_ID IN (4085, 4086, 4087, 4088)
THEN
LN_LENGTH := NVL (LENGTH (TO_CHAR (P_COMMENTS)), 0);

IF LN_LENGTH <= 1
THEN
LC_MSG := ‘Comments are Mandatory’;
HR_UTILITY.SET_MESSAGE (800, LC_MSG);
HR_UTILITY.RAISE_ERROR;
END IF;
ELSE
NULL;
END IF;
END XXHW_CREATE_ABS_VAL_P;
END XXHW_ABS_USERHOOK_PKG;

3. Register your procedure with one or more specific user hooks.

We shall use the API_HOOK_ID identified in Step 1 in the parameter p_api_hook_id. Through this API, custom logic will be registered against user hook.

DECLARE
L_API_HOOK_ID NUMBER := 3840;
L_API_HOOK_CALL_ID NUMBER;
L_OBJECT_VERSION_NUMBER NUMBER;
L_SEQUENCE NUMBER;
BEGIN
SELECT HR_API_HOOKS_S.NEXTVAL INTO L_SEQUENCE FROM DUAL;

HR_API_HOOK_CALL_API.CREATE_API_HOOK_CALL (
P_VALIDATE => FALSE,
P_EFFECTIVE_DATE => SYSDATE – 10,
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 => ‘XXHW_ABS_USERHOOK_PKG’, –CUSTOM PACKAGE
P_CALL_PROCEDURE => ‘XXHW_CREATE_ABS_VAL_P’, — CUSTOM PROCEDURE
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);
END;

 

After this step, you shall be able to see the reference of your custom package/ procedure in table HR_API_HOOK_CALLS. You can check it by using following query

SELECT *
FROM HR_API_HOOK_CALLS
WHERE api_hook_id = 3840;

4. Run the pre-processor program

Run pre-processor script hrahkone.sql with module name as parameter (PER_TOP/admin/sql/hrahkone.sql).It compile API hook. After running this your APIhook Package should have custom procedure call.

or

DECLARE
L_API_MODULE_ID NUMBER := 1731;
BEGIN
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);
END;

Alternately you can use the following API to run the pre-processor

At this level, your user hook is implemented and should work as per your requriement.
If you change your custom package body, you dont need to run the pre-processor again but if you change the procedure signature, you will need to run the pre-processory again,

 

Delete custom code from APIuser Hook

Get Hook Call ID and Object Version_number

SELECT api_hook_call_id,object_version_number
FROM HR_API_HOOK_CALLS
WHERE call_package = ‘LSG_USERHOOK_PKG’
AND call_procedure = UPPER(‘LSG_CREATE_ABS_VAL_P’)

DECLARE
L_API_MODULE_ID NUMBER := 1731;
BEGIN
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);
END;

Note : In case if you are facing any error cross check the same parameters are there in the seeded package.

Source learned from

Thank You.

Advertisements

About pacesettergraam

A good and realistic person

Posted on July 13, 2017, in Functional, Oracle, oracle apps, oracle apps hrms and tagged , , , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: