Tuesday, 23 April 2013

Running Concurrent Program from OAF Page


package oracle.apps.ap.oie.policy.upload.server;

import com.sun.java.util.collections.ArrayList;
import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.cp.request.ConcurrentRequest;
import oracle.apps.fnd.cp.request.RequestSubmissionException;


public class UploadAMImpl extends OAApplicationModuleImpl
{
  public void handleStartUpload()
  {
    OADBTransactionImpl localOADBTransactionImpl = (OADBTransactionImpl)getOADBTransaction();
    Connection localConnection = localOADBTransactionImpl.getJdbcConnection();
    ConcurrentRequest localConcurrentRequest = new ConcurrentRequest(localConnection);
    Vector localVector = getArgList();
    try
    {
      int i = localConcurrentRequest.submitRequest("SQLAP", "APWUPDM", null, null, false, localVector);
      localConnection.commit();
      ((UploadParamsVORowImpl)getUploadParamsVO().first()).setRequestId(new Number(i));
    }
    catch (SQLException localSQLException)
    {
      throw new OAException("SQLAP", "FND_XXX1");
    }
    catch (RequestSubmissionException localRequestSubmissionException)
    {
      throw new OAException("SQLAP", "FND_XXX2");
    }
  }

/*
Vector vparam = new Vector(); //Added
int requestId = cr.submitRequest(applnName, cpName, cpDesc, null, false, vparam);
tx.commit();
return requestId;
}
catch (RequestSubmissionException e)
{
throw new OAException(e.toString(),OAException.ERROR);
}
}*/
 
}

Friday, 19 April 2013

WF START


A workflow can be initiated from PL/SQL using 2 methods,
LaunchProcess and StartProcess.

Launch Process

CREATE OR REPLACE PACKAGE launchwflow_pkg
AS
   PROCEDURE launchwf;
END launchwflow_pkg;
/

CREATE OR REPLACE PACKAGE BODY launchwflow_pkg
AS
   PROCEDURE launchwf
   IS
      l_wfsequence   NUMBER;
   BEGIN
      l_wfsequence := '123456';
      -- Kick off the workflow
      wf_engine.launchprocess (itemtype      => '<item_type>',
                               itemkey       => l_wfsequence,
                               process       => '<process_name>',
                               userkey       => 'XX-'||l_wfsequence,
                               owner         => 'SYSADMIN'
                              );
      COMMIT;
      RETURN;
   END launchwf;
END launchwflow_pkg;
/
 

Start Process

CREATE OR REPLACE PACKAGE BODY wflowproc
AS
   PROCEDURE start_test_wf
   IS
      ret_stat            NUMBER;
      l_wfsequence        NUMBER;
      l_itemtype          VARCHAR2 (40);
      l_process           VARCHAR2 (40);
      l_userkey           VARCHAR2 (40);
      l_owner             VARCHAR2 (40);
      l_parent_itemtype   VARCHAR2 (40);
      l_parent_itemkey    VARCHAR2 (40);
   BEGIN
      l_itemtype := 'TEST_WF';
      l_process := 'TEST_PROCESS';
      l_userkey := 'ABCD1234';
      l_owner := 'SYSADMIN';
      l_wfsequence := '12345';
      -- Create the workflow process instance
      wf_engine.createprocess (itemtype        => l_itemtype,
                               itemkey         => l_wfsequence,
                               process         => l_process,
                               user_key        => NULL,
                               owner_role      => NULL
                              );
      -- Set the user key of the workflow (the user key can be set in the
      -- CreateProcess step also. Then this step will not be required)
      wf_engine.setitemuserkey (itemtype      => l_itemtype,
                                itemkey       => l_wfsequence,
                                userkey       => l_userkey
                               );
      -- Set the workflow item owner
      wf_engine.setitemowner (itemtype      => l_itemtype,
                              itemkey       => l_wfsequence,
                              owner         => l_owner
                             );
      -- Set the initial values for the attributes
      wf_engine.setitemattrtext (itemtype      => l_itemtype,
                                 itemkey       => l_wfsequence,
                                 aname         => 'REQUESTOR',
                                 avalue        => 'OPERATIONS'
                                );
      wf_engine.setitemattrtext (itemtype      => l_itemtype,
                                 itemkey       => l_wfsequence,
                                 aname         => 'APPROVER',
                                 avalue        => 'MANAGER'
                                );
      -- If the workflow we are about to execute is going to be a child process
                  -- for another workflow then we need to connect the running parent process
      wf_engine.setitemparent (itemtype             => l_itemtype,
                               itemkey              => l_wfsequence,
                               parent_itemtype      => l_parent_itemtype,
                               parent_itemkey       => l_parent_itemkey,
                               parent_context       => NULL
                              );
      -- Kick off the workflow
      wf_engine.startprocess (itemtype      => l_itemtype,
                              itemkey       => l_wfsequence);
      COMMIT;
   END start_test_wf;
END wflowproc;
/

Monday, 11 March 2013

Workflow APIs for writing Diagnostic

API for writing Diagnostics


refer: http://docs.oracle.com/cd/B12037_01/workflow.101/b10286/corapi06.htm#a_context

CONTEXT

Syntax
procedure CONTEXT (
          pkg_name IN VARCHAR2,
     proc_name IN VARCHAR2,
     arg1      IN VARCHAR2 DEFAULT '*none*',
     arg2      IN VARCHAR2 DEFAULT '*none*',
     arg3      IN VARCHAR2 DEFAULT '*none*',
     arg4      IN VARCHAR2 DEFAULT '*none*',
     arg5      IN VARCHAR2 DEFAULT '*none*'
                  );

Description
Adds an entry to the error stack to provide context information that helps locate the source of an error. Use this procedure with predefined errors raised by calls to TOKEN( ) and RAISE( ), with custom-defined exceptions, or even without exceptions whenever an error condition is detected.

Arguments (input)
pkg_nameName of the procedure package.
proc_nameProcedure or function name.
arg1First IN argument.
argnnth IN argument.

Example 1/*PL/SQL procedures called by function activities can use the WF_CORE APIs to raise and catch errors the same way the Workflow Engine does.*/

package My_Package is
procedure MySubFunction(
  arg1 in varchar2,
  arg2 in varchar2)
is
...
begin
  if (<error condition>) then
    Wf_Core.Token('ARG1', arg1);
    Wf_Core.Token('ARG2', arg2);
    Wf_Core.Raise('ERROR_NAME');
  end if;
  ...
exception
  when others then
    Wf_Core.Context('My_Package', 'MySubFunction', arg1, arg2);
    raise;
end MySubFunction;

procedure MyFunction(
  itemtype in varchar2,
  itemkey in varchar2,
  actid in number,
  funcmode in varchar2,
  result out varchar2)
is
...
begin
  ...
  begin
    MySubFunction(arg1, arg2);
  exception
    when others then
      if (Wf_Core.Error_Name = 'ERROR_NAME') then
        -- This is an error I wish to ignore.
        Wf_Core.Clear;
      else
        raise;
      end if;
   end;
   ...
exception
  when others then
    Wf_Core.Context('My_Package', 'MyFunction', itemtype, itemkey, to_char(actid), funmode);
    raise;
end MyFunction;


Thursday, 28 February 2013

calling procedure in Controller



      if (paramOAPageContext.getParameter("submit_button_id") != null)
      {
        OAApplicationModule localOAApplicationModule2 = paramOAPageContext.getApplicationModule(paramOAWebBean);
         localNumber = null;
         try {
           localNumber = new Number(paramOAPageContext.getDecryptedParameter("ReportHeaderId"));
         }
         catch (SQLException localSQLException2)
         {
         }
       
         if (localNumber != null)
         {
         OADBTransactionImpl  dbtrx =   (OADBTransactionImpl)localOAApplicationModule2.getOADBTransaction();
         String message_out = null;
          String str = "BEGIN xx_custom_pkg.xx_proc( p_report_header_id => :1 , p_message => :2 );END; ";
          CallableStatement localCallableStatement = dbtrx.createCallableStatement(str, 1);
          try
          {
            localCallableStatement.setInt(1, localNumber.intValue());
            localCallableStatement.registerOutParameter(2, Types.VARCHAR);
            localCallableStatement.execute();
            message_out = localCallableStatement.getString(2);
          }
          catch (SQLException localException2)
          {
              paramOAPageContext.writeDiagnostics(this,"abhishek > catch "+localException2,6);
          }
       
         }
}

Tuesday, 26 February 2013

create a submit button on page


add the code in process request for adding a submit button dynamically, can then catch the event in processformrequest.

 public void processRequest(OAPageContext paramOAPageContext, OAWebBean paramOAWebBean)
    {
OASubmitButtonBean xx_submitButton =(OASubmitButtonBean)createWebBean(paramOAPageContext,OAWebBeanConstants.BUTTON_SUBMIT_BEAN, null, "xx_submitButton");
        xx_submitButton.setLabel("NEW_BUTTON");
        xx_submitButton.setText("NEW_BUTTON");
        xx_submitButton.setID("NEW_BUTTON");
        paramOAWebBean.addIndexedChild(xx_submitButton);
     
        super.processRequest(paramOAPageContext, paramOAWebBean);
    }


in PFR

        if (oapagecontext.getParameter("xx_submitButton")!= null)
        {
            try
            {
            NavigationUtility.forwardToPage(oapagecontext, "GeneralInformationPG", null);
            }
            catch(Exception e2)
            {
                oapagecontext.writeDiagnostics(this, "abhishek > xx_button is clicked> catch"+e2, 6); 
            }
        }

View Object on the fly in VORowImpl class


    public String xxfield()
    {
    Number HeaderId = getReportHeaderId();
    String s2= null;

OAApplicationModuleImpl localOAApplicationModuleImpl = (OAApplicationModuleImpl)getApplicationModule();

OADBTransactionImpl localOADBTransactionImpl = (OADBTransactionImpl)localOAApplicationModuleImpl.getOADBTransaction();

     String s1= " select attribute11 from ap_expense_report_headers_all where report_header_id = :1 ";
   
        if (localOAApplicationModuleImpl.findViewObject("xxProjectVO") != null)
{
    oracle.jbo.ViewObject viewobject =  localOAApplicationModuleImpl.findViewObject("xxProjectVO");
            viewobject.remove();
        }
     
        oracle.jbo.ViewObject viewobject = localOAApplicationModuleImpl.createViewObjectFromQueryStmt("xxProjectVO", s1);

        viewobject.setWhereClauseParam(0, HeaderId);
        Object obj = null;
        viewobject.executeQuery();
        if (viewobject.hasNext())
        {
            oracle.jbo.Row row = viewobject.next();
            if (row.getAttribute(0) != null) {
                try {
                    s2 = row.getAttribute(0).toString();
                } catch (Exception E2) {
                }
            }
        }
        viewobject.remove();
        return s2;
    }

Catching the OAException.wrapperException


warp exceptions can be caught using the below code


  OAException t1 = OAException.wrapperException(localException);
  paramOAPageContext.writeDiagnostics(this,"abhishek> "+t1.getExceptions(),6);
  Throwable athrowable[] = t1.getExceptions();

 if (athrowable != null)
   {
 paramOAPageContext.writeDiagnostics(this,"abhishek > "+athrowable.length,6);
         for(int i = 0; i < athrowable.length; i++)
                 {                          
                   if(athrowable[i] instanceof OAException)
                   {
paramOAPageContext.writeDiagnostics(this,"abhishek > "+i,6);
paramOAPageContext.writeDiagnostics(this,"abhishek> "+OAException)athrowable[i]).getMessage(),6);
                            }
                        }
                   
                    }

--focus on the method getExceptions()