Sunday, September 7, 2014

Application Module Extension in OAF

Like the Controller extension, AM extension is also not supported by Oracle. However for some business needs we have to extend it sometimes.
In this exercise we have taken our “Data Entry OAF page” can be found @https://blogs.oracle.com/prajkumar/entry/insert_data_oaf_page to extend application module i.e. InsertAM
This AM can be found under below BC4J packageprajkumar.oracle.apps.fnd.insertdemo.server.InsertAM


Why we are extending AM:-
This InsertAM contains an apply method which subsequently commits the transaction.
public void apply()
{
 getTransaction().commit();
}
Our business need is to capture user name and user id at runtime and insert it into a custom audit table for audit purpose

Here is Audit Table script --
CREATE TABLE xx_audit
(   -- -------------------
    -- Data Columns
    -- --------------------  
    user_id                  VARCHAR(50),
    user_name            VARCHAR(50),
    -- -------------------
    -- Who Columns
    -- ------------------- 
    last_update_date   DATE        NOT NULL,
    last_updated_by    NUMBER  NOT NULL,
    creation_date         DATE        NOT NULL,
    created_by              NUMBER  NOT NULL,
    last_update_login   NUMBER
);

Steps to Extend Application Module (AM)
1. Create a New Application Module (AM)
Right Click on InsertDemo > New > ADF Business Components > Application Module
Package -- prajkumar.oracle.apps.fnd.insertdemo.server
Name -- ExtendedAM
Extends -- prajkumar.oracle.apps.fnd.insertdemo.server.InsertAM






Write following code in ExtendedAMImpl.java
import oracle.apps.fnd.framework.OAException;
import java.sql.PreparedStatement;
import java.sql.Connection;
public class ExtendedAMImpl extends InsertAMImpl
{
 ....

 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.setDate(5, d);
   stmt.setInt(6, getOADBTransaction().getUserId());
   stmt.setInt(7, getOADBTransaction().getUserId());
   stmt.execute();
  }
 
  catch(Exception exception)
  {
   throw new OAException("Error in Staffing Query"+exception, OAException.ERROR); 
  } 
 super.apply();
 }
}

2. Perform AM Substitution
Double Click on InsertDemo.jpx
Business Components > Substitutions



3. After substitution it will modify *.jpx
In our case it will modify InsertDemo.jpx at project location
i.e. -- D:\xxxx\jdevhome\jdev\myclasses

4. Migrate/ Import the modified jpx
Open Command Prompt and go to following location of your projectD:\xxxx\jdevbin\oaext\bin






5. Congratulation you have successfully finished. Run Your InsertPG page and Test Your Work