Tuesday, 28 November 2006

Raise a Business Event from your OAF Page

After quite a while of inactivity, due partly to a frantic schedule and the addition of a new obsession in the form of my new mountain bike, I am back on the horse and very excited to start blogging again. A Big thanks to Steven Chan for profiling the Oracle EBD Developer on his blog, just the kick I needed to get going again.

I recently had the opportunity to present the 11i/2.6 Implement Oracle Workflow course at Oracle South Africa, which turned me onto business events in a big way. Now I have previously blogged about launching an Oracle Workflow process from an OAF page using the oracle.apps.fnd.framework.webui.OANavigation class. In this post I would like to demonstrate how we can raise a business event through the Oracle Business Event System (OBES), which enables you to utilize the extensive functionality of the OBES to launch workflow processes and perform a number of diverse actions.

import oracle.apps.fnd.wf.bes.BusinessEvent;
import oracle.apps.fnd.wf.bes.BusinessEventException;
....
...
..
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processFormRequest(pageContext, webBean);

if (pageContext.getParameter("Submit") != null)
{
// Get Transaction
OAApplicationModule am = pageContext.getApplicationModule(webBean);
OADBTransactionImpl oadbTrx = (OADBTransactionImpl) am.getOADBTransaction();

// Create BE Object
String eventName = "companyabc.oracle.apps.xx.event.createrequest";
String eventKey = "1001-1";

BusinessEvent busEvent = new BusinessEvent(eventName, eventKey);

try
{
// Set Event Property
busEvent.setStringProperty("XX_TRX_TYPE", "NEW_REQUEST");

// Raise Event
busEvent.raise(oadbTrx.getAppsContext().getJDBCConnection());
}
catch (BusinessEventException exception)
{
// Set Message Tokens
MessageToken[] tokens =
{ new MessageToken("EVENT_EXCEPTION",
exception.toString())
};

OAException eventErrorMessage = new OAException("XX",
"XX_RAISE_EVENT_ERROR", tokens);

oadbTrx.rollback();
....
...
..
}

oadbTrx.commit();
....
...
..
}
}
}