Monday, January 31, 2011

OAF - Creating Runtime ViewObject

Code to create viewobject dynamically at runtime:

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

OAApplicationModule am = pageContext.getApplicationModule(webBean);

// Before you create the VO, check if any instances of the VO object exists or not.
ViewObject checkQVO = am.findViewObject("Your VO Name");
if (checkQVO != null) {
// if one exists then delete that view object.
checkQVO.remove();
}

// Now dynamically create the view object with your custom query using createViewObjectFromQueryStmt method.

checkQVO = am.createViewObjectFromQueryStmt("Your VO Name", "SELECT count(*) as rec_count FROM emp WHERE person"
+"_id = :1");

//NOTE: split the column name into two where need to break the line, otherwise it will give you runtime error. For instance if you change the where clause to be
"SELECT... WHERE person_id "
+= :1");. This will lead to runtime error.

checkQVO.setWhereClauseParams(null);
checkQVO.setWhereClauseParam(0, suppReqId); // pass the input value
checkQVO.executeQuery(); // execute the query

Row checkQRow = checkQVO.getRowAtRangeIndex(0);
if (checkQRow != null) {
int checkQCount = ((Number)checkQRow.getAttribute(0)).intValue();
if (checkQCount == 0) {
throw new OAException("< Type your error message here...>");
}
}

1 comment:

GAMESH TAWADE said...

After using this I can firmly say that I am really satisfied with the product and it really met my expectations.
Click this know next page