Monday, 23 January 2017

Add Attachment field in OAF

Steps to add Attachment field in OAF.
-------------------------------------------
1. For creating Attachment , first we need to create Entity in Application.
Steps to Create Entity:
-----------------------
1.Login into Application --> Ak HTML Forms Resp--> AK Entities
Click on Create Button .
Enter Mandatory fields such as Table Name,Application Id, Entity Id and First PK Attribute Name.
First PK Attribute Name should be primary key of the Table.
2. Once we attach any item ,this Entity name and Primary key values will get stored in 'entity_name' and 'pk1_value' columns of 'FND_ATTACHED_DOCUMENTS' table along with the attachment .
-----------------
2. Create an item of type Attachment Link to any region in OAF Page. Give View Object in View Instance property of BC4J. This table in View object should be same as the table name given while creating entity.
3. If we want to store attachment after adding, update 'Automatic Save' Property as 'True' in the property Inspector. Otherwise if we do commit , attached document will get stored in FND_ATTACHED_DOCUMENTS table.
4.Once we create Attachment Link Item entity Map will be created along with Primary keys and CategoryMap.
5. In Primary key Item , Update view attribute property with Primary key.
6. In Category Map Item , update Category property with MISC (Miscellaneous).






Sunday, 22 January 2017

Creating Password Item Field in OAF

 Password field should be hidden while entering as this is secured. We can create Hidden field in OAF.

steps to create Hidden field for Password:
----------------------------------------------------
1.create a messageTextInput Item field.
2.Update secret property of Item in 'Security' column of Property Inspector as 'True'.


Wednesday, 18 January 2017

Calling Payment Gateway from OAF Page

For Any transactions we need to call Payment Gateway Link from OAF Page.
Make sure Your Application Link is whitelisted by PaymentGateway company,  before calling Payment Gateway url.

we need to call PaymentGateway Url from JSP Page by Passing required parameters to JSP Page from OAF Page using below statement.

pageContext.setForwardURL("/OA_HTML/PaymentGateway.jsp", null, (byte)0, null, localHashMap, true, "Y", (byte)99);



Here 'billDeskRequest.jsp' is custom JSP Page developed in webContent.
Below is the code in 'PaymentGateway.jsp':
--------------------------------------------------

  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%
String UserName=" ";
%>
<HTML>

 <HEAD>

  <TITLE>Redirecting to Payment Gateway Page</TITLE>

  <script type="text/javascript">

  function submit(){
UserName = document.getElementById("userNameParam").value; //get the parameter value
 var formsub=document.PAYMENT_GATEWAY_FORM_NAME;
  formsub.submit(); //Submit Form
 
  }
  </script>
 </HEAD>


 <BODY onload="submit()"> //call submit function once we load jsp page

 <script type="text/javascript">


 </script>
 <input type="hidden" id="userNameParam" value="<%=request.getParameter("params")%>"/> //get the parameter value from OAF page controller which is sent using hashMap

<%  String str=request.getParameter("params");%>

 <% try {%>
<form name='PAYMENT_GATEWAY_FORM_NAME' method='GET' action='PAYMENT_GATEWAY_URL'>


<div>
  <input type='hidden' name='msg' value='<%=str%>'>

</div>
</form>

<% }
catch ( Throwable e)
{
out.println("Runtime error in JSP");
     
}
%>
 </BODY>
</HTML>


Calling webservices from OAF Page

We can call webservices directly from OAF Page. Or we can call webservices from SQL procedure and invoke that procedure from our OAF Page.
Here we are calling webservices from Oracle procedure and calling that procedure from OAF Page.

SQL Procedure:
-----------------

create or replace PROCEDURE invoke_soaservice_p(
    ARG0 IN VARCHAR2 , --
    ARG1 IN VARCHAR2 ,--
    ARG2 IN VARCHAR2 , --
    ARG3 IN VARCHAR2 , --
    ARG4 IN VARCHAR2 , --
    arg5 IN VARCHAR2 , -- Remarks
    result OUT VARCHAR2)
AS
  PRAGMA AUTONOMOUS_TRANSACTION;
  --//===========================================================================
  --Variable declaration
  --//===========================================================================
  --lv_org_id             VARCHAR2(255) := FND_PROFILE.VALUE('ORG_ID');
  lv_soap_request VARCHAR2(30000);
  lv_soap_respond VARCHAR2(30000);
  lv_soap_request_xml XMLTYPE;
  http_req UTL_HTTP.REQ;
  http_resp UTL_HTTP.RESP;
  l_return VARCHAR2(30000);


  vErrorCode    VARCHAR2(100);
  vErrorMessage VARCHAR2(500);
  vXml Xmltype;

'http://10.127.9.14:8080/emas2/services/authenticateWS?wsdl';
  p_soawsdl         VARCHAR2(500) := 'WADL_LINK'; --WSDL Link
  pn_datetime       VARCHAR2(200);
  lv_user_id        VARCHAR2(250);
  lv_passwd         VARCHAR2(250);
  l_url             VARCHAR2(250):= 'null';
  l_id              NUMBER;
  lv_dms_bse_path   VARCHAR2(240);
  lv_dms_department VARCHAR2(240);
BEGIN
  dbms_output.enable(1000000);

  SELECT TO_CHAR(sysdate,'DD-MON-YYYY HH:RR:MM') INTO pn_datetime FROM dual;


  /*--------------  Invoke Register webservice to register the user----------------- */
  lv_soap_request:= '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ds="http://ds.ws.emas/">
<soapenv:Header/>
<soapenv:Body>
<ds:WEBSERVICE_NAME>
<arg0>'||arg0||'</arg0>   //pass parameters to webservice
<arg1>'||arg1||'</arg1>
<arg2>'||arg2||'</arg2>
<arg3>'||arg3||'</arg3>
<arg4>'||arg4||'</arg4>
<arg5>'||arg5||'</arg5>
<arg6>true</arg6>
</ds:WEBSERVICE_NAME>
</soapenv:Body>
</soapenv:Envelope>';

  SELECT TO_CHAR(sysdate,'DD-MON-YYYY HH:RR:MM') INTO pn_datetime FROM dual;
 
  --//===========================================================================
  --Creating the request
  --//===========================================================================
  http_req:= UTL_HTTP.begin_request(p_soawsdl , 'POST' , 'HTTP/1.0');

  SELECT TO_CHAR(sysdate,'DD-MON-YYYY HH:RR:MM') INTO pn_datetime FROM dual;
  --dbms_output.put_line('After Calling http '||pn_datetime);
  --//===========================================================================
  -- since we are dealing with plain text in XML documents
  --//===========================================================================
  UTL_HTTP.set_header(http_req, 'Content-Type', 'text/xml');
  UTL_HTTP.set_header(http_req, 'Content-Length', LENGTH(lv_soap_request));
  --//===========================================================================
  -- required to specify this is a SOAP communication
  --//===========================================================================
  UTL_HTTP.set_header(http_req, 'SOAPAction', 'process');
  UTL_HTTP.write_text(http_req, lv_soap_request);
  SELECT TO_CHAR(sysdate,'DD-MON-YYYY HH:RR:MM') INTO pn_datetime FROM dual;
  -- dbms_output.put_line('After SOAP Process '||pn_datetime);
  --//===========================================================================
  --If the web service is syncronous then it will wait for the response
  --//===========================================================================

  http_resp := UTL_HTTP.GET_RESPONSE(http_req);
  UTL_HTTP.READ_TEXT(http_resp, lv_soap_respond);
  UTL_HTTP.END_RESPONSE(http_resp);
  lv_soap_request_xml:= xmltype(lv_soap_respond);  //webservice will return result in SOAP response format

  /*------------------  Remove SOAP headers and get the Result value------------- */
  SELECT extractValue(lv_soap_request_xml, '//return', ' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://ds.ws.emas/"') RETURN
  INTO l_return
  FROM DUAL;  //use extractValue method to extract output from SOAP response


  result := l_return; //Assign result to variable

  COMMIT;

  SELECT TO_CHAR(SYSDATE,'DD-MON-YYYY HH:RR:MM')
  INTO pn_datetime
  FROM dual;

EXCEPTION
WHEN UTL_HTTP.end_of_body THEN
  UTL_HTTP.END_RESPONSE(http_resp);
  -- errbuf := 'Call to webservice Completed Successfully';
  -- retcode := 0 ;
WHEN UTL_HTTP.request_failed THEN
  dbms_output.put_line('Request Failed:' ||UTL_HTTP.GET_DETAILED_SQLERRM);
  -- errbuf := 'EXCEPTION :UTL_HTTP.request_failed';
  -- retcode := 2 ;
WHEN UTL_HTTP.http_server_error THEN
  dbms_output.put_line('Server Error:'||UTL_HTTP.GET_DETAILED_SQLERRM);
  -- errbuf := 'EXCEPTION :UTL_HTTP.http_server_error';
  -- retcode := 2 ;
WHEN UTL_HTTP.http_client_error THEN
  dbms_output.put_line('Client Error:'||UTL_HTTP.GET_DETAILED_SQLERRM);
  /* errbuf := 'EXCEPTION:UTL_HTTP.http_client_error';
  retcode := 2 ;*/
WHEN OTHERS THEN
  dbms_output.put_line(SUBSTR(SQLERRM,1,255));
  /*  errbuf := 'EXCEPTION :Others';
  retcode := 2 ;*/
END Invoke_soaservice_p;

Call this procedure using CallableStatement In OADBTransaction class in OAF.


Tuesday, 17 January 2017

Calling Appltes from OAF Page.

For calling Applet from OAF, first we need java class file which invokes Applet. If the java file is single, does not depend on any other class files, then add this java file in MyProjects folder and compile from Jdeveloper. call Method of class file, which invokes applet from OAF controller.
If java file depends on other class files, then add jar file which contains all the required java files to Library in jdeveloper.

Adding Jar file to Library in Jdeveloper:
-----------------------------------------------
Right click on ProjectName--> Project properties-->  Click on Add Jar/Directory -->select the Jar file --> click on OK

Import jar file in the controller using import statement.

If we want to pass the output of applet to another control file , then its better to call applet from JSP page and invoke this jsp from OAF. JSP supports both client and server applications.


Steps To Call Applets from OAF Page:
---------------------------------------------

1. Call Jsp Page from OAF page which invokes Applets by using setForwardURL Method.

     pageContext.setForwardURL("/OA_HTML/SupplierSign.jsp",
     null,
     OAWebBeanConstants.KEEP_MENU_CONTEXT,
     null,
     hm, //HashMap
     true, // Retain AM
     OAWebBeanConstants.ADD_BREAD_CRUMB_YES, // Show breadcrumbs
     OAWebBeanConstants.IGNORE_MESSAGES);
Pass required parameters using HashMap.

2. Create Jsp page under 'web Content' in Jdeveloper Project.
Right Click on Web Content --> New-->webTier -->Jsp -->select Jsp from Items window and click on Ok.
A wizard will be opened . Click on Next , Give File Name ,Directory should be OA_HTML.
Click on Next -->select error page option as 'Do not use an error page to handle uncaught exceptions in this file' -->Click on Next -->Next-->Next-->Finish
3.Click on Source tab below the jsp page.
4. For Invoking Applets we should migrate required Jar and JS files to /OA_HTML path in the server.
5. Find below code in Jsp to invoke Appltes and send Output of the Applet to Another Page.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=windows-1252"%>


<html>
<head>
<script src="/OA_HTML/JAVA_SCRIPT_FILE" language="javascript" type="text/javascript"></script>

<script type="text/javascript">
var a;
var b;
var UserName;



/*  Submit Function definition which calls on body load */
function Submit()
{
/* Fetch values */
     UserName = document.getElementById("userNameParam").value;
   
    /* If userName is not null then */
if(UserName != '')
{
a= document.websignerapplet; //Create an object for websignerapplet class
websignerapplet.open(XMLData , "Login" , "sign","attached", "emasSubmit()", "emasCancel()"); // Call open method in websignerapplet class
}
    /* If UserName is null then */
else
{
alert('Please enter username to Sign'); //give an alert
return false;
}
  }

/* If User clicks on Sign then call  emasSubmit function */
  function emasSubmit()
{  

 
    var loginForm = document.frmsubmitDSC; //Create an object for Form
var returnVal = JAVA_CLASS.METHOD(); //Call getGeneratedSignature method to get SIgnData
 
   /* Assign values to Form Variable */
loginForm.signeddata.value = returnVal ;
 
    loginForm.username.value=UserName;
 
 

   loginForm.submit(); //Submit Login FOrm
 
  }

/* If User Clicks on Cancel */
  function emasCancel()
  {
   alert('emas cancelled'); //Give an alert
 
  }
 
</script>
</head>

<body onLoad="Submit()"> <%-- Call  Submit function on body load --%>

<%-- Fetch Values  --%>
<input type="hidden" id="userNameParam" value="<%=request.getParameter("Username")%>"/>


<div id="javaRequiredDiv"></div>
<script type="text/javascript">

var contextPath = "/OA_HTML/JAR_FILE"; //Get Jar file
if( deployJava.versionCheck("1.6+")==false ) {
var java_message = 'Websigner requires JRE1.5 or higher. Please download it from <a href="http://10.80.100.146:8088/websigner4.0/jre6u21.exe">Click here</a> to download jre. <br>Once Installation is done. Close the browser and relogin.';
if (document.all)  {
javaRequiredDiv.innerHTML=java_message;
} else if (document.getElementById){
rng = document.createRange();
el = document.getElementById("javaRequiredDiv");
rng.setStartBefore(el);
htmlFrag = rng.createContextualFragment(java_message);
while (el.hasChildNodes()) {
el.removeChild(el.lastChild);
}
el.appendChild(htmlFrag);
}
} else {
var attributes = {
code :'emas.WebsignerApplet.class',
archive : contextPath,
width :1,
height :1,
name : 'websignerapplet'
};
var parameters = {
MAYSCRIPT : 'true',
scriptable : 'true',
enableExpiryCheck : 'true',
                        regexFilterIssuerName : '',
                        enableEncipherCheck : 'ALL',
certificateClass : '0'
};
var version = '1.5';
deployJava.runApplet(attributes, parameters, version);
}
</script>

<% try {%>

<!-- <TR>

<TD class="content"><a href="#" onclick="Submit()">Enroll With Digital Signature Certificate</a>&nbsp;</TD>      #VA1

</TR> -->

<div class="box">
  <FORM name="frmsubmitDSC" action="/OA_HTML/EmpAuthSubmit4.jsp" method="POST">  <%-- Redirect to EmpAuthSubmit4.jsp which invokes webservices to Authenticate Employee --%>
    <div>
    <%-- Pass variables to EmpAuthSubmit4.jsp --%>
      <input type="hidden" value="" name="signeddata">
      <input type="hidden" value="" name="AuctionHeaderId">
      <input type="hidden" value="" name="userId">
      <input type="hidden" value="" name="username">
      <input type="hidden" value="" name="DBUser">
      <input type="hidden" value="" name="DBPwd">
      <input type="hidden" value="" name="Host">
      <input type="hidden" value="" name="port">
      <input type="hidden" value="" name="Sid">
   
    </div>
 
  </FORM>
</div>


<% }
catch ( Throwable e)
{
out.println("Runtime error in JSP");
}
%>
 
</body>
</html>