User Hooks

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

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.

Custom Hooks to Implement Freight Terms as Pricing Qualifier in


iStore
Email ThisBlogThis!Share to TwitterShare to FacebookShare to Pinterest
User Hooks are a feature that allows customizing the application in a way that is less invasive and that
can be easily disabled for diagnosing problems with the customization. Hooks are code that is
conditionally executed by some application packages. The condition is that the hook has to be enabled.

Hook calls are interleaved in some of ASO APIs, mostly on public APIs. There are two types of Hooks:
Pre-processing Hooks: Are hooks that execute (if enabled) before the API does any actual processing.
These are good for modifying/adding information so the API can proceed with that change in place.
These hooks are of type B (from Before)
Post-processing Hooks: Are hooks that execute (if enabled) after the API did all processing. Post hooks
are usually good for cleanup of a pre-hook or for further processing after the vanilla API has finished
work. These hooks are of type A (from After).
Below are the Steps to Implement Custom Hooks in ASO .
Requirement for Implementation in my Case - In my example I want to use Freight Terms at the iStore to
be used as Qualifier to derive the item price in Shopping Cart in iStore, but Freight Terms is not
supported as Qualifier for iStore ,and to fulfilfill this requirement , I have implemented custom hook to
used Freight Terms as Qualifier from the iStore.
Implementation Steps
To implement this custom hook, I have used ASO Pre-user hook API to
populateASO_PRICING_INT.G_HEADER_REC.freight_terms_code prior to the pricing call.(I have
referred metalink note 400550.1 for my implementation).
Step#1
Create the Package Body ASO_QUOTE_CUHK (Package Specification for this Package already exists in
System).Make sure all the functions that are available in the specifications got created in the Body
Step#2Modify the Package Body
In Procedure Create_quote_PRE(
Add following Code
----------------BEGIN
P_hd_Shipment_Rec.FREIGHT_TERMS_CODE := 'Due'; -- IMPORTANT ( Write the code to populate
Freight Term from iStore).
x_return_Status:='S';
END;
-----------------PLEASE , please make sure you add "x_return_Status:='S'"
Step#3Similarly in Procedure Update_quote_PRE , Add
BEGIN
If P_Hd_Shipment_Tbl.Count>0 Then
P_Hd_Shipment_Tbl(1).Freight_Terms_Code := 'Due'; -- IMPORTANT , we need to populate the Value
from iStore
IF aso_debug_pub.g_debug_flag = 'Y' THEN
Aso_Debug_Pub.Add('P_hd_Shipment_tbl(1).FREIGHT_TERMS_CODE:
'||P_Hd_Shipment_Tbl(1).Freight_Terms_Code);
End If;
x_return_Status:='S';

end if;
END;
PLEASE , please make sure you add "x_return_Status:='S'"
Step#4- Run
Select * From Jtf_User_Hooks
Where Pkg_Name Like 'ASO_QUOTE_PUB'
And User_Hook_Type = 'C'
and api_name in ('CREATE_QUOTE', 'UPDATE_QUOTE').
1. and verify that we have data for api_name in ('CREATE_QUOTE', 'UPDATE_QUOTE') and
User_hook_type =C and Processing type = B and A.
2. If we don't have data for api_name in ('CREATE_QUOTE', 'UPDATE_QUOTE') then we need to run
asocruhk.sql.
Step#5Execute
Update Jtf_User_Hooks
Set Execute_Flag = 'Y'
Where Upper(Pkg_Name) = 'ASO_QUOTE_PUB'
And UPPER(API_NAME) = 'CREATE_QUOTE'
And User_Hook_Type = 'C'
and processing_type='B'
Update Jtf_User_Hooks
Set Execute_Flag = 'Y'
Where Upper(Pkg_Name) = 'ASO_QUOTE_PUB'
And Upper(Api_Name) = 'UPDATE_QUOTE'
And User_Hook_Type = 'C'
and processing_type='B'
Thats all , after successful implementations of above steps ,my customer was able to use Freight
Charges Captured at iStore as Qualifier to derive the Price.

Hey, Here is some basic informations of the PRE or POST User Hooks.
I am explaing the details with an example shown below:
Requirement: Need to update few extra attributes(additional informations in the order header level) while
capturing order in Order Management through iStore (only if the order is placed through iStore)
So here we can use the Submit_quote_PRE procedure in the ASO_QUOTE_CUHK package. If we need to

update or do anything after placing the order instead of the PRE we can use the POST
hook Submit_quote_POST.
Sample code is added below

PROCEDURE Submit_quote_PRE(
p_control_rec
IN OUT NOCOPY ASO_QUOTE_PUB.Submit_Control_Rec_Type,
P_Qte_Header_Id
IN OUT NOCOPY NUMBER,
X_Return_Status
OUT VARCHAR2,
X_Msg_Count
OUT NUMBER,
X_Msg_Data
OUT VARCHAR2
) AS
BEGIN
/* START - custom code */
x_return_status := FND_API.G_RET_STS_SUCCESS;
IF FND_GLOBAL.application_short_name = 'IBE' THEN
/*user custom update or logic should be added here .......*/
END IF;
EXCEPTION
WHEN OTHERS THEN
x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
IF aso_debug_pub.g_debug_flag = 'Y' THEN
aso_debug_pub.add('ASO_QUOTE_CUHK.Submit_Quote_Pre: Exception '||substr(sqlerrm,1,80),
1,'N');
END IF;
/* END - Custom code */
END Submit_quote_PRE;
After this next step is to Enable the USer Hook by executing the below SQL
update JTF_USER_HOOKS
set EXECUTE_FLAG = 'Y'
where PKG_NAME = 'ASO_QUOTE_PUB'
and API_NAME = 'SUBMIT_QUOTE'
and user_hook_type = 'C'
and processing_type = 'B';
if you check the JTF_USER_HOOKS table closer you will find rows as shown below
USER_HOOK_ID PKG_NAME API_NAME PRODUCT_CODE PROCESSING_TYPE
EXECUTE_FLAG
USER_HOOK_TYPE
1009
1011
1008
1010

ASO_QUOTE_PUB
ASO_QUOTE_PUB
ASO_QUOTE_PUB
ASO_QUOTE_PUB

SUBMIT_QUOTE
SUBMIT_QUOTE
SUBMIT_QUOTE
SUBMIT_QUOTE

ASO
ASO
ASO
ASO

A
A
B
B

N
N
Y
N

C
V
C
V

Then you may have few more questions like,


What does the A & B stand for in processing type and what does C & V stand for in user_hook_type?
Here is the answers..

Processing type A means AFTER, B means BEFORE

User hook type C is Custom one that we can modify, V is Vertical one we may not change these type of
hooks
So normally we update the User Hooks of type C by updating the EXECUTE_FLAG from N to Y.
hope this will give you some basic idea about the user Hooks, If need more details or any clarifications
feel free to reach me....
IF (JTF_USR_HKS.ok_to_execute (G_PKG_NAME,
l_api_name,
'B',
'V'))
THEN
ASO_APR_VUHK.get_all_approvers_PRE (
p_object_id
=> p_object_id,
p_object_type
=> p_object_type,
p_application_id => p_application_id,
x_return_status => x_return_status,
x_msg_count
=> x_msg_count,
x_msg_data
=> x_msg_data
);

IF JTF_USR_HKS.Ok_to_execute(G_PKG_NAME, l_api_name, 'B', 'C' ) THEN


csi_gen_utility_pvt.put_line('Calling CSI_ITEM_INSTANCE_CUHK.Create_Item_Instance_Pre ..');
CSI_ITEM_INSTANCE_CUHK.Create_Item_Instance_Pre
(
p_api_version
=> 1.0
,p_commit
=> fnd_api.g_false
,p_init_msg_list
=> fnd_api.g_false
,p_validation_level
=> fnd_api.g_valid_level_full
,p_instance_rec
=> p_instance_rec
,p_ext_attrib_values_tbl => p_ext_attrib_values_tbl
,p_party_tbl
=> p_party_tbl
,p_account_tbl
=> p_account_tbl
,p_pricing_attrib_tbl
=> p_pricing_attrib_tbl
,p_org_assignments_tbl
=> p_org_assignments_tbl
,p_asset_assignment_tbl => p_asset_assignment_tbl
,p_txn_rec
=> p_txn_rec
,x_return_status
=> x_return_status
,x_msg_count
=> x_msg_count
,x_msg_data
=> x_msg_data
);

You might also like