Like the Controller extension, AM extension is also not supported by Oracle. However for some business needs we have to extend it sometime.
In this exercise we have taken the standard LabSolutions project (shipped in Oracle Tutorial) for extending application module i.e. EmployeeAM.
This AM can be found under below BC4J package
oracle.apps.fnd.framework.toolbox.labsolutions.server.EmployeeAM
Why we are extending AM:-
This EmployeeAM contains an apply method which subsequently commits the transaction.
//This is standard apply method in EmployeeAM that we are overriding. public void apply() { getTransaction().commit(); }
Our business need is to capture user name and user id at runtime and insert it into a custom table for AUDIT PURPOSE.
Here is the table script
CREATE TABLE xx_audit (user_id VARCHAR(50), user_name VARCHAR(50), last_update_date DATE, last_update_login NUMBER, last_updated_by NUMBER, creation_date DATE, created_by NUMBER);
Brief Steps of AM Extension with screenshots:-
Step 1:
First create a new workspace and a project for extension
Step 2:
Create two BC4J packages as shown below
oracle.apps.fnd.framework.toolbox.labsolutions.server
This will have the standard AM. Copy the Standard AM files to the BC4J package created above.
and
xx.oracle.apps.fnd.framework.toolbox.labsolutions.server
This package will contain the extended AM.
Step 3:
Now create a new Application module in custom package and set its extends property as shown below
Now in XXEmployeeAMImpl we are overriding the apply method to store the data in custom table.
import oracle.apps.fnd.framework.OAException; import java.sql.PreparedStatement; import java.sql.Connection; public class XXEmployeeAMImpl extends EmployeeAMImpl { public void apply() { java.sql.Date d = getOADBTransaction().getCurrentDBDate().dateValue(); try { Connection conn = getOADBTransaction().getJdbcConnection(); String Query = "insert into xx_audit values(:1,:2,:3,:4,:5,:6,:7)"; PreparedStatement stmt = conn.prepareStatement(Query); stmt.setInt(1, getOADBTransaction().getUserId()); stmt.setString(2, getOADBTransaction().getUserName()); stmt.setDate(3, d); stmt.setInt(4, getOADBTransaction().getUserId()); stmt.setInt(5, getOADBTransaction().getUserId()); stmt.setDate(6, d); stmt.setInt(7, getOADBTransaction().getUserId()); stmt.execute(); } catch(Exception exception) { throw new OAException("Error in Staffing Query"+exception, OAException.ERROR); } super.apply(); } }
Step 4:
Perform the AM substitution
Double click on project.jpx to open below model window
Step 5:
Run jpximport command
C:\jdevbin\jdev\bin>jpximport C:\jdevhome\jdev\myprojects\LabSolutions.jpx -user Id 1 -username apps -password apps -dbconnection "(description = (address_list = (address = (community = tcp.world)(protocol = tcp)(host =ANIL.apps.com)(port = 1521)))(connect_data = (sid = VIS)))" Imported document : /oracle/apps/fnd/framework/toolbox/labsolutions/server/custo mizations/site/0/EmployeeAM Import completed successfully
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.