Friday, April 19, 2019

Oracle OAF Absance - Personalizaton & Extension for Checking If Attachement available.


ADD Controller Extension


Navigation :- Employee Self-Service ->  Leave Management


Create a new leave request then  Click on Personalize page


Update the extension in the below field.



Controller Code :
========================================

package xx.oracle.apps.per.selfservice.absence.webui;

import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.OAViewObject;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.per.selfservice.absence.webui.AbsenceCreateCO;
import oracle.jbo.ViewObject;

public class XxHRAbsCreateCOEx extends AbsenceCreateCO {
 public XxHRAbsCreateCOEx() {}

 public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
   OAApplicationModule am = pageContext.getRootApplicationModule();
   OAViewObject absenceVO = (OAViewObject)am.findViewObject("AbsenceVO");
                                         
   if("HrNext".equals(pageContext.getParameter("_FORM_SUBMIT_BUTTON")))
                        {
                       
                            String absenceAttendanceTypeId = absenceVO.first().getAttribute("AbsenceAttendanceTypeId").toString();
                           
                            String sqlLeaveTypeLookup= "SELECT decode(count(*),'0',null,count(*)) from FND_LOOKUP_VALUES_VL where lookup_type = 'XXHR_ABSANCE_EXN_LEAVE_TYPE' AND MEANING = " + absenceAttendanceTypeId;
                           
                            if (am.findViewObject("XXLeaveTypeLookup") != null) {
                                 am.findViewObject("XXLeaveTypeLookup").remove();
                               }
                               ViewObject getLeaveType = am.createViewObjectFromQueryStmt("XXLeaveTypeLookup", sqlLeaveTypeLookup);
                               getLeaveType.executeQuery();
   //&&"2091".equals(absenceAttendanceTypeId))
                        if (getLeaveType.first().getAttribute(0) != null)
       {
                             boolean b= checkAttachment( pageContext, webBean);
                             if (b){super.processFormRequest(pageContext, webBean);}
                             else{
                                //    throw new OAException(" AbsenceAttendanceTypeId :-  " + absenceAttendanceTypeId + " Leave Type Count :- " + getLeaveType.first().getAttribute(0) ,OAException.ERROR);
                                OAException message = new OAException("PER","XXHR_ABSANCE_ATTACHEMENT_MS",null ,OAException.ERROR,null);
                                pageContext.putDialogMessage(message);
                                }
                             }
                            else{super.processFormRequest(pageContext, webBean);}
                        }
   else{super.processFormRequest(pageContext, webBean);}
  }
 
 public boolean checkAttachment(OAPageContext oapagecontext,OAWebBean oawebbean)
  {
   OAApplicationModule am = oapagecontext.getRootApplicationModule();
   String amName = "";
   String objectivesAMName = "OAAttachmentsAM";
   String objectiveVOName = "FndAttachedDocumentsDomExtensionVO";
   String nestedAMArray[] = am.getApplicationModuleNames();
   oapagecontext.writeDiagnostics(this,"Root AM=>"+am.getName() + " Child AMs=>"+ nestedAMArray.length,1);
   OAApplicationModule currentAM = null;
   OAApplicationModule currentAM2 = null;
   OAApplicationModule attAM = null;
   OAViewObject vo = null;
   OAViewObject attvo = null;
   boolean isAttachmentFound = false;
   currentAM = am;
                            for(int i = 0; i < nestedAMArray.length; i++)
                                {
                                amName = nestedAMArray[i];
                                oapagecontext.writeDiagnostics(this,"Nested AM Name=>"+amName + "and amName.indexOf(objectivesAMName) "+amName.indexOf(objectivesAMName),1);
                                currentAM = (OAApplicationModule)am.findApplicationModule(amName);
                                String nestedAMArray2[] = currentAM.getApplicationModuleNames();
                                    for (String s: currentAM.getApplicationModuleNames())
                                    {
                                    currentAM2 = (OAApplicationModule)currentAM.findApplicationModule(s);
                                        for (String s2: currentAM2.getViewObjectNames())
                                        {
                                        // get attachments VO Name
                                            if ("Attach_0_FndAttachedDocumentsDomExtensionVO".equalsIgnoreCase(s2) )
                                            {
                                            attvo = (OAViewObject)currentAM2.findViewObject("Attach_0_FndAttachedDocumentsDomExtensionVO");
                                                    if(attvo!=null && attvo.getFetchedRowCount() > 0)
                                                    {
                                                    oapagecontext.writeDiagnostics(this,"View object name  Row Count"+attvo.getFetchedRowCount(),1);
                                                    isAttachmentFound = true;
                                                    break;
                                                    }
                                            }
                                        }
                                    }
                                //Get the view names
                                oapagecontext.writeDiagnostics(this,"Nested AM Value "+currentAM.getName(),1);
                                if(!(amName.indexOf(objectivesAMName)==-1))
                                {
                                    String[] viewNames = currentAM.getViewObjectNames();
                                    for (int j =0 ;j<viewNames.length ;j++ )
                                    {
                                    if(viewNames[j].indexOf(objectiveVOName) > 0)
                                    {
                                    vo = (OAViewObject)currentAM.findViewObject(viewNames[j]);
                                    if(vo!=null && vo.getFetchedRowCount() > 0)
                                    {
                                    oapagecontext.writeDiagnostics(this,"View object name "+viewNames[j]+" Row Count"+vo.getFetchedRowCount(),1);
                                    isAttachmentFound = true;
                                    break;
                                    }
                                    }
                                    }
                                    oapagecontext.writeDiagnostics(this,"Found Handle to My Nested AM " + amName ,1);
                                    }
                            }
                    return isAttachmentFound;
                }
  }

No comments:

Post a Comment