« Step away from the table...moving from to
in your templates | Main | Well it had to happen.... »
Tuesday
Feb232010

APEX_UTIL ...ready SET JSON

On a recent project we ran across a great place to use apex_util.set_session_state and apex_util.json_from_items. A client wanted an email address to self populate after picking a name from a pop-up LOV. Easy enough but how to do this...options options options...well we could have used jQuery but I decided to use APEX_UTIL because of the existing code on the page. So here is what we did..

First, we added an onChange event to the HTML Form Element Attributes of the popup LOV:

onChange="getEmail(this.value);"

 

Next on to the javascript in the header....

function getEmail(pUser) {
    var get = new htmldb_Get(null,$v('pFlowId'),
                  'APPLICATION_PROCESS=GET_EMAIL',0);
    get.addParam('x01',pUser);
    gReturn = get.get();
    json_SetItems(gReturn);  
}

nothing too complex...just calling an APEX onDemand process and passing over a user name. In return we get an email address as JSON.

Last is the onDemand plsql. We use apex_util.set_session_state and apex_util.json_from_items to set the item and pass over the email address.

DECLARE
  l_userid varchar2(100);
  l_email varchar2(100);
BEGIN
  l_userid := wwv_flow.g_x01;
   
   SELECT email
   into l_email
   FROM my_user_table
   WHERE upper(user_account) = upper(l_userid);
   
apex_util.set_session_state('P100_APPROVER_EMAIL',l_email);
apex_util.json_from_items('P100_APPROVER_EMAIL');

end;

 

Now when a user selects from the pop-up LOV, the email address is auto filled into the approver email text field.

Nothing earth shattering here but rather helpful when you want to have values filled in on the page automatically giving that web 2.0 fresh feeling. Also on Chris Beck's blog is a bigger implementation of JSON calls to a apex shuttle.

PrintView Printer Friendly Version

EmailEmail Article to Friend

References (2)

References allow you to track sources for this article, as well as articles that were written in response to this article.

Reader Comments (1)

Very concise.

Just what I was attempting to do the other day, but just missing the json component.

All we need now is for the Oracle Apex Documentation to catch up.

March 3, 2010 | Unregistered CommenterScott Wesley

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>