Tuesday, May 28, 2019

Making attachments as mandatory in OAF through CO Extension

The requirement is to stop the user from clicking next button in the TRAIN page if the attachment is not attached. The challenge i faced is attachment will not be committed to database till user click save button at the last step.

import oracle.apps.fnd.framework.webui.beans.message.OAMessageAttachmentLinkBean;

public void processFormRequest(OAPageCntext oapagecontext, OAWebBean oawebbean)
    {
      OAApplicationModule am = oapagecontext.getApplicationModule(oawebbean);
        super.processFormRequest(oapagecontext, oawebbean);
       
            if ("goto".equals(oapagecontext.getParameter(EVENT_PARAM)) || "NavBar".equals(oapagecontext.getParameter(SOURCE_PARAM))) //NavBar is used to get the even t from Train bar.
            {
            oapagecontext.writeDiagnostics(this," first IF condition passed " ,OAFwkConstants.STATEMENT) ;
            if(am != null)
            {   
                OAMessageAttachmentLinkBean localOAMessageAttachmentLinkBean = (OAMessageAttachmentLinkBean)oawebbean.findChildRecursive("Attachments");
               
                if(localOAMessageAttachmentLinkBean != null)
                {
                    String str = (String)localOAMessageAttachmentLinkBean.getAttributeValue(oapagecontext.getRenderingContext(), TEXT_ATTR);
                    oapagecontext.writeDiagnostics(this,"Printing str " +str ,OAFwkConstants.STATEMENT) ;
                    if ("None ".equals(str))
                    {
                            throw new OAException("Please Attach Required Supporting Documents To Process The Invoice.",OAException.ERROR);
                    }
                }
            }
            }

How to get value from Message Styled Text in OAF page

There are 4 ways to get the value of MessageStyled text from OAF page in CO.

First Option
=========
Get the handler of the VO which is used by that field.

import oracle.apps.fnd.framework.OAViewObject;
import oracle.apps.fnd.framework.OARow;

OAViewObject vo = (OAViewObject)am.findViewObject("PosViewHeadersVO");
if(vo != null)
        {
            try
            {
                vo.reset();
                vo.next();
                OARow row = (OARow)vo.getCurrentRow();
                confirm_flag_vo = (String)row.getAttribute("Confirm");
            }
            catch(Exception e)
            {
                oapagecontext.writeDiagnostics(this,"Exception occurred " + e.toString() ,OAFwkConstants.STATEMENT);
            }
        }

Second Option
==============

Get the handler of the bean and use that handler to get the value.

import oracle.apps.fnd.framework.webui.beans.message.OAMessageStyledTextBean;

OAMessageStyledTextBean oaconfirmflag = (OAMessageStyledTextBean)oawebbean.findChildRecursive("PosConfirm");
String confirm_flag_bean = null;
confirm_flag_bean = (String)oaconfirmflag.getText(oapagecontext);

Third Option
===========

Get the handler of the item using getParameter() method.

String confirm_flag_getparam = null;
confirm_flag_getparam = (String)oapagecontext.getParameter("PosConfirm");

Fourth Option
==========
Write a SQL query in your CO and parse the SQL statement. I have used this method in my previous post.