Friday, September 25, 2015

Message File Upload Bean

import oracle.apps.fnd.framework.webui.beans.message.OAMessageFileUploadBean;
import oracle.apps.fnd.framework.webui.OADataBoundValueViewObject;

code in PR for Defaulting the file name to Message File upload bean

PR Code:
OAMessageFileUploadBean attachmentBean = (OAMessageFileUploadBean)webBean.findChildRecursive("UploadItem");
OADataBoundValueViewObject attachmentNameBoundValue = new OADataBoundValueViewObject(attachmentBean, "FileName");
attachmentBean.setAttributeValue(DOWNLOAD_FILE_NAME, attachmentNameBoundValue);

where UploadItem is the Id of the MessaageFileUpload Bean.

PFR Code to get filename when MessageFileUploadBean is used in table Region

    while(vo.hasNext()) 
    {
    Row row=vo.next();
    String StrAttachId="AttachmentRN.UploadItem";
    i=i+1;
    StrAttachId=StrAttachId+i;
    DataObject fileUploadData = pageContext.getNamedDataObject(StrAttachId);
    if(fileUploadData != null)
    {
    strFileName= fileUploadData.selectValue(null,"UPLOAD_FILE_NAME").toString();
    row.setAttribute("FileName",strFileName);
    }
    }



Sunday, June 28, 2015

Making a OAF page read only

Some times we may need to make a oaf page read only in situations like when it is pending for approval etc

for this there is an API; using which we can make all the items in the page read only

lets see how to use that

first import the following package from PO_TOP

import oracle.apps.po.common.webui.ClientUtil;

And call the API as shown below in the process request

ClientUtil.setViewOnlyRecursive(pageContext, webBean);

it will make all the items read only irrespective of any item type

Sunday, June 14, 2015

Switcher in OAF

sometimes we may need to show different images for different rows based on some conditions
like in below image






let's see how to achieve it 
I want to show different images for a different records based on the status column if it is P one image and if its any thing else then another different Image

There is a region called switcher for this type of requirement in oaf

Right click on any table column select switcher 


















Row right click on switcher and add new case

Now right click on case add new item and change the property of it to desired like MessageStyledText, Choice, Image etc. In my case am using a Image 
Add as many cases as many conditions you have
if you have 3 conditions add 3 cases. In my case i have 2 conditions so i am adding two cases
write a Sql query that returns different values for different conditions like below

SELECT emp_id,
       full_name,
       date_of_birth,
       DECODE (gender,  'M', 'Male',  'F', 'Female') Gender,
       email_id,
       status,
       DECODE (status, 'N', 'Enabled', 'Disabled') Update_Enabled,
       marital_status
  FROM emp_master

My Query returns the value Enabled if status is N and Disabled for all other values

I am using the same query in the vo mapped to table

Now change the Id of the Items under case as per the values returned by query.

so give different images for Enabled Item and Disabled Item like in below image

now give the view attribute to Switcher item
here i have give UpdateEnabled as my view attribute because this columns holds the logic to give different values for different row based on the flag

Now write a code to execute query of the vo attached to table on process request then you can get the required output.

Different Image for different rows using this you can handle Update on few rows and disable on few rows.












Thursday, June 4, 2015

Calling Pl/Sql Package,Function,sql Statement in Oaf Code either in AM or in CO

First import the following packages

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;

Calling a Function:
 public void callConcProg(String StrParamString)
 {
String StrRequestId=null;
String programcall=null;
programcall="begin :1 := FND_REQUEST.SUBMIT_REQUEST("+StrParamString+"); end;";
            CallableStatement cs =  getOADBTransaction().createCallableStatement(programcall,-1); 
            try
            { 
            cs.registerOutParameter(1,Types.VARCHAR); 
           //Need to define what type of output is that valid types are Number, Varchar ,Date etc.
            cs.execute(); 
            getOADBTransaction().commit();
           //After execute we can get the value of output value using the following syntax. 
           StrRequestId = cs.getString(1); 
            cs.close(); 
            } 
            catch (SQLException sqle) 
            { 
            throw new OAException("Error in Calling",sqle.toString());
            }
            if(!StrRequestId.equals("0")) 
             {
              errMsg1.add(new OAException(StrRequestId+" request submitted successfully",
              OAException.CONFIRMATION));
             }
        }

Calling a pl/Sql Procedure:

 public void excuteUpload() 
 throws SQLException {  
 OADBTransaction transaction = getOADBTransaction(); 
CallableStatement cs=transaction.createCallableStatement
("begin PACKAGE.UPLOAD_FILE("+transaction.getUserId()+") ; end;", -1);
                     try 
                     {
                       cs.execute();
                       cs.close();
                     }
                     catch(Exception e) 
                     {
                     throw new OAException("Error in Api PACKAGE.UPLOAD_FILE"+e.toString());    
                     }
                     }
Calling a Sql Query;

public void getDBName ( ) 
{
OADBTransaction transaction =this.getOADBTransaction();  
String Query="SELECT NAME FROM V$DATABASE";
try{
PreparedStatement stmt = transaction.createPreparedStatement(Query,0);
for(ResultSet resultset = stmt.executeQuery(); resultset.next();)  
{  
StrDBName        = resultset.getString(1);
//here getString(1) refers first column if you have many u need to use
//getString(2),getString(3) like that and if you had other data types you can use
// getDate(),getNumber() etc.
}  
}  
catch(Exception e) 
{
throw new OAException("Error in Query:"+Query+e,OAException.ERROR);
}
}

Syntax to get Uploaded File Name from Message File Upload Bean

First import DataObject from this package
import oracle.cabo.ui.data.DataObject;

Then make a reference to the MessageFileUpload bean
like below, where MessageFileUpload is the Id of my MessageFileUpload Item

DataObject fileUploadData = pageContext.getNamedDataObject("MessageFileUpload");

so to get file name of uploaded file with extension.

using the following syntax in processFormRequest

String strFileName=null;      
if(fileUploadData != null)
        {
         strFileName= fileUploadData.selectValue(null,"UPLOAD_FILE_NAME").toString();
        }