Friday, May 17, 2013

Call Workflow from OAF Page


Oracle Workflow is tightly integrated with Oracle Apps and it is very common to invoke workflow from OAF Pages too.

The class oracle.apps.fnd.framework.webui.OANavigation provides Java wrappers for Oracle Workflow Engine’s PL/SQL APIs.

It is very simple to invoke Workflow using OAF, again there are two options first using Java wrappers and second through calling PL/SQL procedures but the later approach you can use if you are converting some Oracle Form into OAF form and all the code for Workflow is already ready and tested but if it is new workflow then you should use Java wrappers:

Following piece of code invokes the Workflow from OAF:
import oracle.apps.fnd.framework.webui.OANavigation;
public void launchWorkFlowFromOAF(OAPageContext pageContext)
{
  String wfItemType = “‘XXSR’”;
  String wfProcess = “‘SR_MAIN_PROCESS’”;
  OADBTransaction transaction = getOADBTransaction();
  String Sr_No ;
  String wfItemKey = ” “;

  Sr_No = pageContext.getParameter(“sr_no”);
  wfItemKey = Sr_No+ transaction.getSequenceValue(“xxsr_key_s.NEXTVAL”).toString();
  OANavigation wfClass = new OANavigation();

  // Create Workflow Process
  wfClass.createProcess(pageContext, wfItemType, wfProcess, wfItemKey);

  // Set Number Attribute: SR_NO
  wfClass.setItemAttrNumber( pageContext, wfItemType, wfItemKey, ”SR_NO”, Sr_No);

  // Start Workflow Process
  wfClass.startProcess(pageContext, wfItemType, wfProcess, wfItemKey);
}


If you want to invoke this workflow using callable statement then you have to write code like this:
OAF code:

if(pageContext.getParameter(“btnSubmit”)!=null)
{
  String sql = "BEGIN xx_sr_notf_pkg.invoke_wf (:1); END;";
  String status = null;
  OracleCallableStatement cs = (OracleCallableStatement)
  am.getOADBTransaction().createCallableStatement(sql,1);
  try
  {
    cs.setString(1,srNo);
    cs.execute();
    cs.close();
  }
  catch (Exception ex)
  {
    throw new OAException(ex.getMessage().toString(),
    OAException.ERROR);
  }
  throw new OAException("SR "+srNo+" has been submitted",
  OAException.CONFIRMATION);
}

PL/SQL Code to Invoke Workflow:
PROCEDURE invoke_wf (p_sr_doc_number IN VARCHAR2)
IS
   l_item_key             VARCHAR2 (50);
   BEGIN
        SELECT p_sr_doc_number ||  xxegasr_key_s.NEXTVAL
        INTO l_item_key
        FROM DUAL;
        wf_engine.createprocess ('XXSR', l_item_key, 'SR_MAIN_PROCESS');
        wf_engine.setitemattrnumber(itemtype      => 'XXSR',
                            itemkey       => l_item_key,
                            aname         => 'P_SR_DOC_NO',
                            avalue        => p_sr_doc_number
                           );    
        wf_engine.startprocess ('XXSR', l_item_key);
        COMMIT;
END invoke_wf;

Source:http://dineshnair.wordpress.com/2009/06/02/integrating-workflow-and-oaf/
Related Posts Plugin for WordPress, Blogger...