Creating Java Program Dynamic Fields

This appendix covers the following topics:


Refer to Creating User Defined Dynamic Fields for information on creating user defined dynamic fields.

Database Connection/Transaction

Users can reuse the same database connection (transaction) that is used to generate the proposal document. They can also create their own database connection, connecting to same database or different database. Please see the following sections for explanation of benefits/disadvantages of using each approach.

Reusing the same database connection

If you use the same transaction or database connection, you can get profile option values, user details, or other information, for the user who is generating the proposal. You can get the connection object by using the statement:

Connection con = oaDbTransaction.getJdbcConnection();

Note: There should not be any commits or rollbacks in the Java program, if you are reusing the connection.

Creating new database connection

You can create your own connection, but you cannot use data such as profile option values, or user details. You can create a connection to any database, provided you have access to that database from the middle tier when Oracle Proposals code is running.

View Object

If you have defined a View Object earlier and want to use it to get data from other tables, you need to create it on the transaction and perform the query. Refer to Sample Code Program for details.

If you use the View Object, the BC4J layer prepares the SQL statement. Also, the View Object meta data (SQL statement) is cached, for better performance during subsequent executions.

Registering Your Java Program

After you have written a program, compile the program to get the class file and copy the class file into a directory that is included in the classpath. You can also add a new directory to the classpath, but you will need to restart your apache middle tier(s). Create a dynamic field, choose the type as Java program and then associate the package.class.method with it. Refer to Creating User Defined Dynamic Fields for information on field creation.

When you register the Java program, Oracle Proposals will validate whether the Java class file is accessible to the middle tier and if the method contains Hashtable as an input parameter and returns a String. It is therefore important to follow the preceding steps before creating the dynamic field.

Java Program in Generated Proposal Versions

While generating the proposal version, Oracle Proposals calls the Java program to get the String value and replace the dynamic field with the returned value in the generated document. If there is an error while calling the program, Oracle Proposals replaces the dynamic field with blank space in the generated document.

This sample code program contains two methods.

Sample Code Program

package oracle.apps.prp.example.server;

import java.sql.Connection;

import java.sql.Timestamp;

import java.util.Date;

import java.util.Hashtable;

import oracle.apps.fnd.framework.OAViewObject;

import oracle.apps.fnd.framework.server.OADBTransaction;

import oracle.jbo.Row;

import oracle.jbo.domain.Number;

public class PRPJavaTokenExample


//Empty constructor

public PRPJavaTokenExample()



//Method to get the System Time.

public String getSystemTime(Hashtable hash)


return new Timestamp(new Date().getTime()).toString();


//Method to get the Greeting in User Language.

public String getUserLanguageGreeting(Hashtable hash)


String greeting = "Greetings!";

//Get the Proposal Id. Notice that the proposalId is casted to oracle.jbo.domain.Number

Number proposalId = (Number)hash.get("proposalId");

OAViewObject UserLanguageVO = null;

//get the OADBTransaction

OADBTransaction oaDbTransaction = (OADBTransaction)hash.get("oaDbTransaction");

// Connection con = oaDbTransaction.getJdbcConnection();

//You will need the connection, if you are using JDBC to construct and execute the sql statement.

// Check if the transaction exists

if (oaDbTransaction != null)




// Create the View Object UserLanguageVO and execute the Query.

UserLanguageVO =



while (UserLanguageVO.hasNext())


//Get the first row. This sql only returns one row.

Row rowUserLanguageVO =;

//Get the language code value from the view object.

String languageCode = (String)rowUserLanguageVO.getAttribute("LanguageCode");

if (languageCode.equals("US"))


greeting = "Hello World!!";


else if (languageCode.equals("FR"))


greeting = "Bonjour Monde!";


else if (languageCode.equals("E"))


greeting = "Hola Mundo!";


else if (languageCode.equals("D"))


greeting = "Hallo Welt!";




greeting = "Hello!";



return greeting;


catch (Throwable ex)


return "<Unexpected Error! (Creating VO)>";





return "<Unexpected Error!>";