Json_from_sql

I've found that into FLOWS_030100.wwv_flow_ajax package there are some json procedures, but I don't understand how they work, they're not documented.
Anybody knows how to use these procedures?

I have successfully used the json_from_sql procedure provided in the flows and here is how to use it...
1. First create an ondemand application process. I named mine MAKE_JSON.
2. Inside that process call the json_from_sql procedure like so:
HTMLDB_UTIL.JSON_FROM_SQL('SELECT * FROM table_name');3. Lastly you need to make an ajax call to fire off the application process like so:
  <script type="text/javascript">
      function getJSON()
        var get = new htmldb_Get(null,$v('pFlowId'),'APPLICATION_PROCESS=MAKE_JSON',0);
        var gReturn = get.get();
  </script>4. Here is a sample of the JSON object that is returned from the procedure:
(The structure will resemble the select statement.
This particular table has 3 columns: PK_ID, NAME, LNAME)
  {"row":[{"PK_ID":"0001","NAME":"Scott","LNAME":"Tiger"},
          {"PK_ID":"0002","NAME":"Tyson","LNAME":"Jouglet"}]}5. The code to access the information stored in the structure looks like this:
    $x('item_id').value = row[0].PK_ID; // 0001
    $x('item_id').value = row[0].NAME;  // Scott
    $x('item_id').value = row[0].LNAME; // Tigernull

Similar Messages

  • Passing values to APEX_UTIL.JSON_FROM_SQL

    What I'm trying to do in my OnDemand application process is something like:
    declare
    lv_ename varchar2(10) := 'BLAKE';
    begin
    APEX_UTIL.JSON_FROM_SQL('select empno,ename,job from emp where ename = '||lv_ename||'')
    end;
    What I get is:
    ORA-20001: get_dbms_sql_cursor error ORA-20001: Invalid parsing schema for current workspace ID
    from Application Express 3.1.2.00.02
    -or-
    ORA-20001: get_dbms_sql_cursor error ORA-00904: "BLAKE": invalid identifier
    from Application Express 3.2.0.00.27
    I get the same error message from Application Express 3.1.2.00.02 if I try passing a number rather than a varchar2 but Application Express 3.2.0.00.27 is OK with the number.
    declare
    lv_empno number := 7900;
    begin
    APEX_UTIL.JSON_FROM_SQL('select empno,ename,job from emp where empno = '||lv_empno||'');
    end;
    How do I get a varchar2 value into my WHERE clause?

    Hello,
    Your missing some quotes (but I don't know if this is the correct number of quotes. Print out the statement to see if it is constructed correctly. It should become:
    select empno,ename,job from emp where ename = 'BLAKE'
    APEX_UTIL.JSON_FROM_SQL('select empno,ename,job from emp where ename = '||'''||lv_ename||'''')
    Greetings,
    Roel
    http://roelhartman.blogspot.com/
    You can reward this reply by marking it as either Helpful or Correct ;-)

  • Apex 3.2 group select list

    Hi,
    I just want share this if you are still in older version of Apex and you use jQuery.
    I did made "plugin" for grouped select list
    See sample here
    http://actionet.homelinux.net/htmldb/f?p=100:86
    Plugin source
    ;(function(){
    jQuery.fn.htmldbLovOptGrp=function(o){
    var t=jQuery(this);
    o=jQuery.extend({
      sessionValue:t.val(),
      nullShow:false,
      nullValue:'%null%',
      nullDisplay:'%',
      lovProcess:undefined,
      lovGrpLabel:'GRP',
      lovDisValue:'DIS',
      lovRetValue:'RET',
      loadingTxt:'Loading ...',
      loadingCss:{'width':'80px'}
    },o);
    return lCreSelect(t,o);
    jQuery.htmldbAjax=jQuery.fn.htmldbAjax=function(opt){
    jQuery.ajaxSetup({
      url:'wwv_flow.show',
      dataType:'HTML',
      traditional:true,
      cache:false,
      type:'POST',
      data:{
       p_flow_id:jQuery('#pFlowId').val(),
       p_flow_step_id:jQuery('#pFlowStepId').val(),
       p_instance:jQuery('#pInstance').val()
    return jQuery.ajax(opt);
    jQuery.htmldbJSON=jQuery.fn.htmldbJSON=function(opt,callfn){
    return jQuery.htmldbAjax({dataType:'json',data:opt,success:callfn});
    function lCreSelect(t,o,j){
    t.empty().hide().parent().append(jQuery('<div/>').html(o.loadingTxt).addClass('ui-autocomplete-loading').css(o.loadingCss));
    jQuery.htmldbJSON(jQuery.extend(j,{p_request:'APPLICATION_PROCESS='+o.lovProcess}),function(jd){
      if(o.nullShow){lAppendOpt(t,null,o.nullDisplay,o.nullValue);}
      jQuery.each(jd.row,function(i,d){lAppendOpt(t,d[o.lovGrpLabel],d[o.lovDisValue],d[o.lovRetValue]);});
      t.val(o.sessionValue).trigger('change').show().parent().find('div.ui-autocomplete-loading').remove();
      return t;
    function lAppendOpt(t,l,d,r){
    var o=lCreateOpt(d,r);
    if(l){
      var g=lGetOptGrp(t,l);
      if(g){g.append(o);}
      else{t.append(lCreOptGrp(l).append(o));}
    }else{t.append(o);}return true;
    function lExists(p){return(p.length==1);}
    function lCreateOpt(d,r){return jQuery('<option/>').val(r).html(d);}
    function lCreOptGrp(l){return jQuery('<optgroup/>').attr({'label':l});}
    function lGetOptGrp(t,l){var g=t.find('optgroup[label="'+l+'"]');if(lExists(g)){return g;}else{return false;}}
    })();Copy code and save it to file e.g called jquery.htmldbQuery.js and upload it to workspace Static Files.
    Create new page and blank HTML region.
    Create select list with LOV query
    SELECT null d, null r FROM dualCreate On Demand application process called GET_GRP_LOV like
    DECLARE
    l_sql VARCHAR2(32700);
    BEGIN
    l_sql :='
      SELECT mgr AS grp,
       ename AS dis,
       empno AS ret
      FROM emp
    APEX_UTIL.JSON_FROM_SQL(l_sql);
    END;Place to page HTML header
    <script type="text/javascript" src="#WORKSPACE_IMAGES#jquery.htmldbQuery.js"></script>
    <script type="text/javascript">
    $(function(){
    $('#Px_MY_SELECT').htmldbLovOptGrp({lovProcess:'GET_GRP_LOV'});
    </script>Where Px_MY_SELECT is your select list name.
    As I did say this need you also load jQuery. Apex 4 have jQuery , but if you are on later version see e.g. this blog post
    http://www.oracleapplicationexpress.com/tutorials/66
    I hope this helps someone
    Br,Jari
    Edited by: jarola on Aug 17, 2010 8:44 PM
    Same thing seems to be work also with Apex 4.0
    http://apex.oracle.com/pls/otn/f?p=40323:50
    But if I have understand correctly Apex 4.0 have some build in or better thing to get same result
    Edited by: jarola on Aug 17, 2010 10:54 PM
    copy&paste mistake corrected
    Edited by: jarola on Aug 18, 2010 12:57 AM
    I hope editing post all the time is ok =).
    I have not test this on any other browser than Fire Fox, so all comments are welcome.
    Also I have try create similar plugin for cascading lov. Sample here
    http://actionet.homelinux.net/htmldb/f?p=100:85
    Maybe there is this kind plugins already for Apex 3.x, I have not just seen.
    Also I'm beginner with jQuery so all help and comments is needed
    Edited by: jarola on Aug 18, 2010 2:01 AM
    mistake in guide corrected.

    Hi Matt,
    which version of APEX are you currently on?
    With ApexLib Framework you can have cascading select lists in normal forms, but not in a Report or Tabular Form. Also refreshing a Report when changing a select list doesn't work out of the box. You would need to add some javascript. But i think this isn't what you wanted.
    brgds,
    Peter
    Blog: http://www.oracle-and-apex.com
    ApexLib: http://apexlib.oracleapex.info
    BuilderPlugin: http://builderplugin.oracleapex.info
    Work: http://www.click-click.at

  • Dynamic action - Cache server data

    APEX 4.2.2
    Is there a way to cache server side data in a global (page/document level) Javascript vector (bunch of key-value pairs) (associative array, array of objects or some such)? This way the data can be used by subsequent dynamic actions' Javascript code without querying the server over and over.
    I see that apex_util.json_from_sql is still undocumented after all these years. Are there any examples of using that API to do this sort of thing? Can someone please share?
    Thanks

    https://apex.oracle.com/pls/apex/f?p=57688:24
    I took a shot at this and it seems to work well using Javascript global objects for data storage. Hope this helps someone.
    1. Page attributes - Javascript global variables var gData,gLookup={};2. On-demand application process Get_Emps as apex_util.json_from_sql('select empno,ename from emp');3. Page Load dynamic action to invoke the application process and cache the data var get = new htmldb_Get(null,$v('pFlowId'),'APPLICATION_PROCESS=Get_Emps',$v('pFlowStepId'));
    var retval=get.get();get=null;
    gData=apex.jQuery.parseJSON(retval);
    $.each(gData.row,function(i,obj){
       gLookup[obj.EMPNO]=obj.ENAME;
    });4. EMPNO page item - Standard OnChange dynamic action to SetValue of ENAME page item using the cached data - Javascript expression gLookup[$v(this.triggeringElement)]
    We document something when it is ready to be supported. This specific procedure isn't something we haven't invested in, and thus, per our discretion, have elected not to document or support it at this time.Fair enough.

  • Cascading LOV in a Tabular form

    Hi Guys,
    I have read numerous articles on the generation of cascading LOV's in a tabular form but havent been able to get it working
    I have created an example in my apex workspace at:
    http://apex.oracle.com/pls/apex/f?p=4000:1500
    workspace XXAPPS
    Username guest
    Password demo
    app no 17551
    Page 2
    In my test scenario, I have an emp table, dept table and an office table.
    Within my tabular form(based on the emp table), I have a deptno column and an office column.
    Depending on what the user selects in the deptno column, I would like the corresponding list of offices associated to that dept LOV to be returned in the offices LOV.
    The table structure is
    EMP
    EMPNO
    ENAME
    JOB
    MGR
    HIREDATE
    SAL
    COMM
    DEPTNO
    OFFICE_ID
    DEPT
    DEPTNO
    DNAME
    LOC
    OFFICE
    OFFICE_ID
    OFFICE_NAME
    DEPTNO
    When the user selects a deptno in the LOV I would like that to control the values that are returned in the office LOV.
    I have used Jari's blog post:
    http://dbswh.webhop.net/dbswh/f?p=BLOG:READ:0::::ARTICLE:2003800346210117
    but as you can see it isn't quite working in that the office LOV is not returning anything.
    I am pretty new new to JavaScript and jQuery so am no doubt doing something wrong as some of the steps are causing errors and are confusing me a bit e.g. step2 is causing the page to return blank (I have commented the code out in the example)
    Any help would be greatly appreciated.
    Thanks
    Edited by: Cashy on 07-Mar-2012 04:05

    Hi fac,
    That is the full code as per the Jari's link on http://dbswh.webhop.net/dbswh/f?p=BLOG:READ:0::::ARTICLE:2003800346210117 (last but one section of instructions).
    I have got the id of the elements (f07 and f06) by using IE Developer toolbar and have passed those into the dynamic action.
    The child element is now just showing loading...
    It seems to me that the on demand process is not being called because I changed the code to:
    DECLARE
    l_sql VARCHAR2(32700);
    BEGIN
    IF APEX_APPLICATION.G_x01 IS NOT NULL OR APEX_APPLICATION.G_x01 IS NULL
    THEN raise_application_error(-20001,'code gets here');
    l_sql := 'SELECT competency_id AS RET
    ,competency_description AS DIS
    FROM XXMEL_FOCUS_COMPETENTCIES
    WHERE competency_category_id = ' || APEX_APPLICATION.G_x01 || '
    ORDER BY competency_description
    APEX_UTIL.JSON_FROM_SQL(l_sql);
    ELSE
    HTP.prn('{"row":[]}');
    END IF;
    just to see if the code is getting to the process but the error message that I put in the PL/SQL is not firing.
    Chris

  • Color entries in select list

    Say I have a dataset like (status_code,status_desc,color). A select list uses the code & desc but I would like to use the color of each status to be used as the background color for that entry. Patrick shows how to do this for a simple case right using the Element properties but how would this be done in my example?
    I was thinking of using apex_util.json_from_sql to get the status_code & color in a Before Footer process and use Javascript to set the colors. But I couldn't figure out how to use the JSON as an associative array i.e. row[status_code] = color.
    Comments? Thanks

    Hello Vikas,
    >> But when the page is submitted, Complete will be stored in session state and this is not one of the values returned by the LOV query …
    Yes, sorry about that, I forgot I’m also using a Post Calculation Computation on the item, which calls a function that builds a matching value to the LOV. Something like:
    select_list_color(:P1_SELECT);The body of this function is, of course, depends on the way/source to derive the status color. In my case, it looks like:
    function "SELECT_LIST_COLOR" (
      p_color_name in VARCHAR2
    ) return VARCHAR2
    is
      l_color_code  varchar2(20) := '';
    BEGIN
      if p_color_name is not null then
        select code into l_color_code
        from mis_color_code
        where color = p_color_name;
      end if;
      return p_color_name || ':' || l_color_code;
    END;
    >> … so the LOV item needs to have "Show Extra Values" turned on
    That’s not good enough as the Extra Value doesn’t include color code so the select list entry will not be colored (which defeat the original purpose).
    >> Or maybe you have an after-submit computation to join the Complete and Green again so page rendering continues to work fine.
    That’s also not good enough. First, I don’t want to impair the integrity/consistency of the session state. Secondly, if, for example, you are using ARF to populate the select list item, you’ll have the same problem, so after-submit computation is not enough.
    The best solution I could think of is to use the Post Calculation Computation. So far it’s working very good.
    Your solution, using AJAX, is also valid (and more importantly, it seems to work for you) however, in this specific scenario, where all the information is actually available to you pre-rendering the page, another trip to the database seems too costly (especially in my case, where some of the communication is over the Internet, using very crowded lines).
    Regards,
    Arie.
    &diams; Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.
    &diams; Forthcoming book about APEX: Oracle Application Express 3.2 – The Essentials and More

  • Tooltip for IR report(Apex 3.2)header column

    Hello Everyone,
    I need help in setting up a tooltip for report hearder in interactive reports. I tried the following methods:
    1) By assigning a div title for column Deptno(This code is taken from the html source of IR report column):
    <th id="DEPTNO" >
    <div id="apexir_DEPTNO" onclick="gReport.controls.widget(this.id)" style="">
    Deptno
    <div title="Tooltip text for first div">&lt/div>
    </div>&lt/th>
    2) With javascript & css : I put the following line on report header edit section:
    < a class="tooltip" href="#">Tooltip<span>This is the crazy little Easy Tooltip Text.</span></a>
    Nothing really solved my problem. Is there any easy way of resolving the above issue?
    Thanks in advance for your help.
    - Parveen
    Edited by: Parveen Sehrawat on Mar 14, 2012 2:58 PM

    Hi,
    Blog post example do not work with APEX 3.2
    By default on APEX 3.2 you do not have jQuery and dynamic actions.
    You can do same with APEX 3.2 if you use htmldbQuery plugin
    http://sourceforge.net/projects/htmldbquery/
    Integrate plugin and jQuery to APEX
    Then create page process before regions
    DECLARE
      l_sql VARCHAR2(32700);
    BEGIN
      l_sql := '
      SELECT COLUMN_ALIAS,
        HELP_TEXT
       FROM APEX_APPLICATION_PAGE_IR_COL
      WHERE APPLICATION_ID = :APP_ID
        AND PAGE_ID = :APP_PAGE_ID
        AND HELP_TEXT IS NOT NULL
      HTP.p ('<script type="text/javascript">');
      -- Create JSON object.
      HTP.prn ('var gIrColHelp = $u_eval(''(');
      APEX_UTIL.JSON_FROM_SQL(l_sql);
      HTP.prn (')'');');
      HTP.p ('</script>');
    END;Add to page HTML header
    <script type="text/javascript">
    $.htmldbIrReady(function(){
    $.each(gIrColHelp.row,function(i,jd){
      $($x("apexir_"+jd.COLUMN_ALIAS)).parent("th").attr({"title":jd.HELP_TEXT});
    </script>See working example
    http://actionet.homelinux.net/htmldb/lspdemo?p=220
    Regards,
    Jari
    http://dbswh.webhop.net/dbswh/f?p=BLOG:HOME:0
    Edited by: jarola on Mar 15, 2012 4:53 PM

  • Is this OnDemand process secure?

    Hello,
    I'm using the jQuery autocomplete method along with an OnDemand application process to return a list of user's based on whats being typed in my input box. I want to make sure that it's not vulnerable to sql injecton. Can anyone tell me if this is safe or not?
    Application Express 3.2.1.00.12
    Here's the code in question.
    Application Process:
    DECLARE
      l_sql VARCHAR2(32000);
    BEGIN
      l_sql := '
       select full_name, position_name, rowid
         from emp
        where 1=1
          and upper(full_name) like ''%'|| upper(apex_application.g_x01) || '%''
       order by 1
      APEX_UTIL.JSON_FROM_SQL(l_sql);
    EXCEPTION
      WHEN OTHERS THEN
        HTP.p ('{"row":[]}');
    END;jQuery:
    <script type="text/javascript">
    $(function(){
    $("#P300_NEXT_APPROVER").autocomplete({
      source: function(r,s){
       $.ajax({
        type:"POST",
        url:"wwv_flow.show",
        dataType:"json",
        data:{
         p_flow_id:$v('pFlowId'),
         p_instance:$v('pInstance'),
         p_flow_step_id:$v('pFlowStepId'),
         x01:$v('P300_NEXT_APPROVER'),
         p_request:"APPLICATION_PROCESS=EmployeeAutocomplete"},
        success:function(d){
         s($.map(d.row,function(l){
          return{
           label:l.FULL_NAME +" - "+ l.POSITION_NAME, number:l.ROWID
      select: function( event, ui ) {
       $( "#P300_NEXT_APPROVER" ).addClass("hide").val("");
       $( "#P300_NEXT_APPROVER_TITLE" ).html( ui.item.label);
       $( "#P300_NEXT_APPROVER_ROWID" ).val( ui.item.number);
       return false;
      delay: 500,
      minlength: 2,
      open:function(){$(this).removeClass("ui-corner-all").addClass("ui-corner-top");},
      close:function(){$(this).removeClass("ui-corner-top").addClass("ui-corner-all");}});
    </script>Thanks in advance,
    Daniel

    Hi,
    You could create application item. Set app item Session State Protection to Restricted - May not be set from browser
    Then change process
    DECLARE
      l_sql VARCHAR2(32000);
    BEGIN
      :MY_APP_ITEM := '%' || upper(apex_application.g_x01) || '%';
      l_sql := '
       select full_name, position_name, rowid
         from emp
        where 1=1
          and upper(full_name) like :MY_APP_ITEM
       order by 1
      APEX_UTIL.JSON_FROM_SQL(l_sql);
    EXCEPTION
      WHEN OTHERS THEN
        HTP.p ('{"row":[]}');
    END;Regards,
    Jari
    My Blog: http://dbswh.webhop.net/htmldb/f?p=BLOG:HOME:0
    Twitter: http://www.twitter.com/jariolai

  • Jquery autocomplete

    Hi jari,
    Thanks for your reply.
    i am displaying first_name from employees table.
    i am sending you my code.
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/themes/redmond/jquery-ui.css" type="text/css" />
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("jquery", "1.4.2");
      google.load("jqueryui", "1.8.0");
    </script>
    <script type="text/javascript">
    $(function(){
    $("#P500_FIRST_NAME").autocomplete({ // Change P73_STATE to your text item id
      source: function(r,s){
       $.ajax({
        type:"POST",
        url:"wwv_flow.show",
        dataType:"json",
        data:{
         p_flow_id:$v('pFlowId'),
         p_instance:$v('pInstance'),
         p_flow_step_id:$v('pFlowStepId'),
         x01:$v('P500_FIRST_NAME'), // Change P73_STATE to your text item id
         p_request:"APPLICATION_PROCESS=P500_AUTOCOMPLETE"},// Change P73_AUTOCOMPLETE to your On Demand Process name
        success:function(d){
         s($.map(d.row,function(l){
          return{
           label:l.FIRST_NAME,value:l.FIRST_NAME // Change STATE_NAME to column name you return from On Demand Process
      open:function(){$(this).removeClass("ui-corner-all").addClass("ui-corner-top");},
      close:function(){$(this).removeClass("ui-corner-top").addClass("ui-corner-all");}});
    </script>Application process
    DECLARE
      l_sql VARCHAR2(32000);
    BEGIN
      l_sql := '
        SELECT FIRST_NAME
        FROM EMPLOYEES WHERE FIRST_NAME LIKE ''' || UPPER(APEX_APPLICATION.G_x01) || '%''
        ORDER BY 1
      APEX_UTIL.JSON_FROM_SQL(l_sql);
    EXCEPTION
      WHEN OTHERS THEN
        HTP.p ('{"row":[]}');
    END;Thanks & Regards
    Vedant

    Hi jari,
    Thank you so much for your help. Now its working.
    jari i have one more question related to jquery autocomplete.
    i am following http://tylermuth.wordpress.com/2010/03/16/jquery-autocomplete-for-apex/ this link to fetch mutiple value based on search field.
    i have followed all the steps but i did some changes. i have deleted
    x02: 'foo',
                x03: $('#P2_DEPARTMENT').val() lines from code because i was not getting why these lines are used.if this is required what changes i do in my code so its work fine for me?
    i am sending you code
    i am fetching FIRST_NAME,LAST_NAME,EMAIL FROM EMPLOYEES TABLE.
    my code is not working.
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="#WORKSPACE_IMAGES#jquery.autocompleteApex1.1.js"></script>
    <link rel="stylesheet" type="text/css" href="#WORKSPACE_IMAGES#jquery.autocomplete.css" />
    <script type="text/javascript">
    $(document).ready( function() {
        $("#P501_SEARCH").autocomplete('APEX', {
                apexProcess: 'EMPLOYEES_EXTENDED',
                width: 400,
                multiple: false,
                matchContains: true,
                cacheLength: 1,
                max: 100,
                delay: 150,
                minChars: 1,
                matchSubset: false
        // the following statement sends the result to multiple items on the page.
        $("#P501_SEARCH").result(function(event, data, formatted) {
            if (data){
                $("#P501_FIRST_NAME").val(data[1]);
                 $("#P501_LAST_NAME").val(data[2]);
                $("#P501_EMAIL").val(data[3]);
    </script>APPLICATION PROCESS
    declare
         l_search varchar2(255);
    begin
        execute immediate 'alter session set NLS_SORT=BINARY_CI';
        execute immediate 'alter session set NLS_COMP=LINGUISTIC';
        l_search := replace(wwv_flow.g_x01,'*','%');
        for c1 in (select first_name||' '||last_name name,first_name,last_name,email
                     from employees
                    where first_name like '%'||l_search||'%'
                       or last_name like '%'||l_search||'%')
        loop
            htp.p(c1.name||'|'||c1.first_name||'|'||c1.last_name||'|'||c1.email);
        end loop;
    end;

  • How to detect an error from ajax get

    Hi -- This is in a javascript function.
    I have an object ajaxRequest defined as:
    ajaxRequest = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=LOOKUP_VALUE',0);
    I call the app process as follows:
    ajaxResponse = ajaxRequest.get();
    The app process just looks up a value in the DB based on another. It works fine
    when there's a match. When there's not a match, I can see that the ajaxResponse
    contains "sqlerrm: ORA- ... ". And of course a json.parse fails.
    How can I detect that the get returned an error? I can't just search
    ajaxResponse for an string, right? (It doesn't appear that that object is
    simply treated as a string... )
    Thanks,
    Carol

    hi John -- Sounds good, but I guess I'm not sure how to go about it.
    LOOKUP_VALUE is:
    DECLARE
    -- Set wwv_flow.g_x01, g_x02, g_x03, g_x04 and g_x05 in the
    -- javascript part
    p_source_item_value varchar2(1000) := wwv_flow.g_x01;
    d_source_column_name varchar2(32) := wwv_flow.g_x02;
    d_dest_column_name varchar2(32) := wwv_flow.g_x04;
    d_lookup_table_name varchar2(32) := wwv_flow.g_x05;
    BEGIN
    --Use this to get a JSON string back in the javascript,
    -- based on the SQL query
    APEX_UTIL.JSON_FROM_SQL('SELECT '||d_dest_column_name||' RETURN_VAL FROM '||d_lookup_table_name||'@'||:DB_NAME||' WHERE '||d_source_column_name||' = '''|| p_source_item_value||'''');
    END;
    So, it's returning this JSON object to the javascript. As I said, it works fine when there's a match.
    I'm not sure how to catch an error in the LOOKUP_VALUE process and get it back to the javascript. Ideas?
    Also, even if I do get that going, I'm not sure how to check the returned object for some sort of problem.
    The javascript function code is below. Look for #### for my comments. Essentially, right now, if
    there is an error in the json object (it's showing up as a numeric or value error), the parse fails. So I
    need to detect the problem before the parse. OR, if I can just modify LOOKUP_VALUE to plug in
    something like 'NO MATCH' when there's a problem or no value is found, then I think json.parse will work
    and my page item can just be set to NO MATCH. Does this make sense?
    Here's the function.
    Thanks for your help!
    Carol
    function jsLookupValue(source_item_value, source_column_name, dest_item_name, dest_column_name, lookup_table_name){
    // Continue only if there are valid values
    if (valueOf(source_column_name)&&valueOf(dest_item_name)&&valueOf(dest_column_name)&&valueOf(lookup_table_name)){
    //Check to see if the source_item_value is null (either all spaces or empty
    //If it is, set the dest item to null, but only if it's not already --
    //otherwise we get into a loop.
    source_item_value = trim(source_item_value);
    dest_item_value = trim($v(dest_item_name));
    if (source_item_value.length==0) {
    if (dest_item_value.length != 0) {
    $s(dest_item_name, null);
    }else{
    //This is the AJAX call to the Application Process from step 1
    ajaxRequest = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=LOOKUP_VALUE',0);
    //Here we are adding that x01 parameter we use in the app process with the value of the objecttype_name field
    ajaxRequest.addParam('x01', source_item_value);
    ajaxRequest.addParam('x02', source_column_name);
    ajaxRequest.addParam('x03', dest_item_name);
    ajaxRequest.addParam('x04', dest_column_name);
    ajaxRequest.addParam('x05', lookup_table_name);
    //Now do the actual AJAX call and put the result in ajaxResponse
    ajaxResponse = ajaxRequest.get();
    //Check if there is a response
    if (ajaxResponse) {
    // ######### When there's no row matching the query, this alert shows
    // "sqlerrm: ORA-06502 PL/SQL: numeric or value error"
    // Can I somehow check ajaxResponse for that string?
    alert("Response from APP process: " + ajaxResponse);
    //We need to format the JSON return string and put it in a JSON object
    // the formatting is done by a function in the external JSON library
    // the jsonobj can be used to retrieve the data returned by the App process
    // ######### If there was an error, the parse fails
    var jsonobj= ajaxResponse.parseJSON();
    alert('Filtered returned value from APP process: ' + jsonobj.row[0].RETURN_VAL);
    // And finally, we set the DNAME item with the value of the jsonobj.DNAME
    // an array was created in the object with the name row, so that is why you have to include row[0] to retrieve the data
    if (jsonobj.row[0].RETURN_VAL != $v(dest_item_name)) {
    // ########## I'd like to just set the destination item w/ something like "NO MATCH"
    // probably regardless of the error...
    $s(dest_item_name, jsonobj.row[0].RETURN_VAL);
    }else{
    //alert ('NOT setting dest item');
    } //not setting
    }else{
    alert('No response from app process');
    } //no response
    } //no source item value
    } //no bad nulls
    } //function

  • Using jquery FullCalendar in APEX with dynamic query

    Hi,
    I am trying to implement jquery FullCalendar in APEX and came across thie following post but I am unable to get the events to work. I would really like to see it working with an Application_Process:
    How we can highlight events in Calendar
    Currently I created an Application Process that simply calls a DB table and convert it into json format.
    DECLARE
    v_sql varchar2(400);
    BEGIN
    v_sql := 'SELECT * FROM CAL_FEED';
    apex_util.json_from_sql(v_sql);
    END;
    But I am unsure how to add the events via an Application_Process.
    I have tried the following in numerious ways (events:function, url feed, etc). It does work if I just do an array but would like it as a dynamic query.
    $('#calendar').fullCalendar({
    events: "http://server:8080/apex/f?p=101:53:4352610578859707:APPLICATION_PROCESS=IAT_TEST_CAL_FEED"
    Thank you in advance,
    Jimmy

    Hi,
    I was able to get the events into Fullcalendar with an Application Process but not sure if this would scale well with alot of events.
    Would someone be able to tell me if there is a better way?
    I am currently using an On Demand Application Process called IAT_TEST_FEED:_
    DECLARE
    lv_cal_list VARCHAR2(16000);
    lv_return_str VARCHAR2(32000);
    BEGIN
    FOR i IN (SELECT "CAL_FEED"."ID" as ID,
    "CAL_FEED"."title" as caltitle,
    "CAL_FEED"."start" as calstart,
    "CAL_FEED"."end" as calend
    FROM "CAL_FEED")
    LOOP
    lv_cal_list := lv_cal_list || '{"id":' || CHR(39) || i.ID || CHR(39) || ',' ||
    ' "title":' || CHR(39) || i.caltitle || CHR(39) || ',' ||
    ' "start":' || CHR(39) || i.calstart || CHR(39) || ',' ||
    ' "end":' || CHR(39) || i.calend || CHR(39) || '},';
    END LOOP;
    lv_return_str := '[' || RTRIM(lv_cal_list,',') || ']';
    htp.prn(lv_return_str);
    EXCEPTION WHEN OTHERS THEN
    htp.prn('error');
    END;
    In a HTML Region on a page within the Region Header:_
    <link rel="stylesheet" type="text/css" href="#WORKSPACE_IMAGES#fullcalendar.css" />
    <script type="text/javascript" src="#WORKSPACE_IMAGES#ui.core.js"></script>
    <script type="text/javascript" src="#WORKSPACE_IMAGES#ui.draggable.js"></script>
    <script type="text/javascript" src="#WORKSPACE_IMAGES#ui.resizable.js"></script>
    <script type="text/javascript" src="#WORKSPACE_IMAGES#jquery.js"></script>
    <script type="text/javascript" src="#WORKSPACE_IMAGES#fullcalendar.js"></script>
    <script type="text/javascript" src="#WORKSPACE_IMAGES#fullcalendar.min.js"></script>
    <script type='text/javascript'>
    $(document).ready(function() {
    $('#calendar').fullCalendar({
    events: function(start, end, callback) {
    $.ajax({
    type: "POST",
    url: "wwv_flow.show",
    dataType: "json",
    data: {
    p_flow_id:$('#pFlowId').val(),
    p_flow_step_id:$('#pFlowStepId').val(),
    p_instance:$('#pInstance').val(),
    p_request:"APPLICATION_PROCESS=IAT_TEST_FEED"
    success:function(calevents){
    $.each(calevents, function(i, calevent){
    $('#calendar').fullCalendar('renderEvent', calevent, true);
    </script>
    The line within the ajax call is basically where my concern would be
    $('#calendar').fullCalendar('renderEvent', calevent, true);
    Thank you,
    Jimmy

  • Accessing LOV in Javascript

    Hi Everyone,
    I'm on Apex 4.1.1 and I have this requirement.
    I have a form where there are multiple select lists and radio buttons which the user uses to configure features of a particular object being created using that form.
    I also have to show a text string that changes dynamically based on the currently made selections to give the users a description of what they have selected.
    I have used javascript to do this and it works fine. However I need help in one feature.
    I have 4 select lists that list colours. Now these colours have abbreviations (for e.g. WHITE -> WHT) which I need to add in the text description. But these abbreviations are available only in a table. I have to get these to the front end for which I thought I'll use a LOV which gets it from the table.
    I want to know if there is a way to access this LOV in a page javascript. If so then how do I do it?
    Any help would be appreciated.
    Regards,
    Arijit
    Edited by: Arijit Kanrar on Feb 7, 2013 12:24 PM
    Edited by: Arijit Kanrar on Feb 7, 2013 12:25 PM

    Example for EMP/DEPT:
    Create a PLSQL region with source:
    htp.p('<script type="text/javascript">');
    htp.p('var gaDepartments = ');
    apex_util.json_from_sql(q'!
    select deptno, dname, loc
    from dept
    htp.p(';');
    htp.p('</script>');This will create an array stored in a global variable.
    I have a tabular form with sql
    select
    "EMPNO",
    "EMPNO" EMPNO_DISPLAY,
    "ENAME",
    "HIREDATE",
    "SAL",
    "DEPTNO"
    from "#OWNER#"."EMP"I changed column "DEPTNO" to be based on an LOV so that a select list is generated and the DNAME column is used as display column.
    I then bind to the onchange event
    $("td[headers='DEPTNO'] select").change(function(){
       var lFind = $(this).val();
       $(gaDepartments.row).each(function(){
          if(this.DEPTNO==lFind){
             alert(this.DNAME + ' is located in ' + this.LOC);
             return false;
    });This will iterate over the objects in the array until it has found the entry associated with the value now selected in the list and alert the dname and loc. Mind the capitalised member names as they are case sensitive.
    Let's say i did this on a page item select list and want to affect another page item. I'd create a dynamic action which fires on change of the select list item. Execute javascript as true action:
       var lFind = $(this.triggeringElement).val();
       $(gaDepartments.row).each(function(){
          if(this.DEPTNO==lFind){
             alert(this.DNAME + ' is located in ' + this.LOC);
             $(this.affectedElements).val(this.DNAME);
             return false;
       });Set the item to be affected in the affected elements region.
    This should allow you to set it up, given that you understand a bit of javascript/jquery and dynamic actions. Otherwise, set up an example on apex.oracle.com!

  • URL not found error executing on-demand app process using APEX_UTIL.JSON

    Hi -- I have an application process that's called by a javascript header function;
    the javascript function is called by an onblur event on an LOV.
    Hopefully I can explain this w/o too much confusion :)
    I'm having the JS do an alert to show the return value of the call to the app process.
    The call to the app process is set up in the following way:
    ajax_request = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=Lookup_Value',0);
    ajaxRequest.addParam('x01', $x('P3_OBJECTTYPE_NAME').value);
    ajaxResponse = ajaxRequest.get();
    The application process LOOKUP_VALUE is:
    DECLARE
    -- We will set wwv_flow.g_x01 in the javascript part
    -- you can use this parameter as a temp. APP ITEM
    p_objecttype_name varchar2(32) := wwv_flow.g_x01;
    BEGIN
    --Use this to get a JSON string back in the javascript, based on the SQL inserted
    APEX_UTIL.JSON_FROM_SQL('SELECT objecttype_id FROM hdb_objecttype_syn WHERE objecttype_name = ''' || p_objecttype_name||'''');
    END;
    The alert in the JS shows the value of ajaxResponse to be the following:
    <!DOCTYPE HTML PUBLIC"-//DTD HTML 2.0//EN">
    <HTML><HEAD>
    <TITLE>404 Not Found </TITLE>
    </HEAD><BODY>
    <H1>Not Found</H1>
    The request URL /pls/apex/ww_flow.show was not found on this server.<P>
    <HR>
    <ADDRESS>Oracle-Application-Server-10g/10.1.2.0.0 Oracle-HTTP-Server Server at
    myservername Port 7777 </ADDRESS>
    </BODY></HTML>
    I'm really not at all sure what could be causing this. Could it have something to do
    w/ compatibility between JSON and my version of APEX (3.0.1.00.06)? Or ... ?
    Thanks,
    Carol

    CarolM2,
    CarolM2 wrote:
    I'm really not at all sure what could be causing this. Could it have something to do
    w/ compatibility between JSON and my version of APEX (3.0.1.00.06)? Or ... ?Whilst this isn't a compatibility issue between JSON itself and APEX 3.0.1.00.6, it is a version related issue. This API, the x01-x10 series globals and 'addParam' were not introduced until 3.1. Also 3.1 introduced the useful JavaScript functions $s and $v which you may have been trying to use (although you didn't show the later part of your JS code so I can't be sure).
    Is it possible for you to upgrade your instance as this will definitely make your life easier with this stuff (and give you interactive reports :-) )? If you cannot upgrade, this is still possible but you'll just need to construct (and output) the JSON string yourself, use 'add' instead of 'addParam', use an application item to store your temporary value and possibly have to write some slightly different JS code to output the response on the client (although again I didn't see that part of your code).
    Please let me know if you need any more help on this.
    Anthony.
    http://anthonyrayner.blogspot.com
    Edited by: Anthony Rayner on Nov 20, 2008 12:04 AM

  • Extjs Trees Json backt to the db

    Hello,
    i am often using Apex Trees. Now i want to replace the trees with extjs trees.
    my tree modell datamodell in the db are two tables
    Hierarchy table
    id -- parent_id -- child_id
    Info Table
    child_id -- name (name of the tree node and leafes)
    FK Constraint is between child_id's
    To create the json with apex_util.json_from_sql is pretty easy.
    When i add nodes, leafes or change the order of the tree (on the client side), i have to write the changes back to the database.
    My question is how to write json back to the db?
    Is there a package out there?
    Is it possible to sync the objects in a specific way (like a data set in .net)
    any help is welcome
    see you
    volker strasser

    Hi Volker
    It's up to you how the data is passed back.
    I have an [extjs editable tree|http://apex.oracle.com/pls/otn/f?p=200801:2000] which can output either JSON or XML data.
    You could very easily pass the XML output back to the database for processing either in a standard form POST, or using AJAX.
    I'm also working on a fully AJAX enabled editable tree, which I'll put up on my demo site in the next few weeks.
    The javascript will be viewable, but the PL/SQL won't be (Oracle programmers already know PL/SQL).
    Mark

  • Need interdependent LOV and text item

    Hi -- I have a table with 2 columns: objecttype_id (the primary key) and objecttype_name.
    In my form for a table that looks up objecttypes from the objecttype table, I need the following:
    - an LOV on objecttype_name that displays the objecttype_id and objecttype_name concatenated, and
    returns the objecttype_name. I have this working.
    - objecttype_id is a text field - needs to allow user to enter data
    - When the objecttype_name is populated by the LOV, I need the objecttype_id text field to be populated with
    the objecttype_id corresponding to the name. This needs to happen without a page submit.
    - When the user types the objecttype_id into the text field (they may know the appropriate ID and not
    want to use the LOV), I need the corresponding name to go into the objecttype_name field. Again, without a
    page submit. There are at least 10 LOVs on this page, and it would be too cumbersome to do a submit after
    each.
    I've done quite a bit of looking around on the forum, but don't see (or recognize) anything that will meet
    these requirements.
    Ideas?
    Thanks,
    Carol

    Hi Carol,
    Let's mix this up a little bit, offcourse you can find examples on the provided links. But there's another very cool way to this. :x So, you can also do this with JSON and AJAX.
    In this example I'll explain how to lookup the DNAME in the DEPT table
    with the DEPTNO. You can use this later as objecttype_name and
    objecttype_id with your own queries!
    1. Create an Application process that looks up your value and give it a name (this one is called DEPTLOOKUP)
    DECLARE
    -- We will set wwv_flow.g_x01 in the javascript part
    -- you can use this parameter as a temp. APP ITEM
    p_deptno varchar2(5) := wwv_flow.g_x01;
    BEGIN
    --Use this to get a JSON string back in the javascript, based on the SQL inserted
    APEX_UTIL.JSON_FROM_SQL('SELECT dname FROM dept WHERE deptno = ' || p_deptno);
    END;
    {code}
    2. On the page, put the following piece of javascript in the header
    *P.S. We need to include the json library to use some JSON features so* *also*
    *include it*
    [code]
    &lt;script LANGUAGE = "JavaScript" src="http://www.json.org/json.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript"&gt;
    // This function will be fired from the field, when data is returned from the LOV
    function lookupDname(){
      // First check if there's a value in the DEPTNO field (otherwise do not execute the rest)
      if ($v('P2_DEPTNO'){
      //This is the AJAX call to the Application Process from step 1
      ajaxRequest = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=DEPTLOOKUP',0);
      //Here we are adding that x01 parameter we use in the app process with the value of the deptno field
      ajaxRequest.addParam('x01', $v('P2_DEPTNO'));
      //Now do the actual AJAX call and put the result in ajaxResponse
      ajaxResponse = ajaxRequest.get();
      //Check if there is a response
      if (ajaxResponse) {
        //We need to format the JSON return string and put it in a JSON object
        // the formatting is done by a function in the external JSON library
        // the jsonobj can be used to retrieve the data returned by the App process
        var jsonobj= ajaxResponse.parseJSON();
        // And finally, we set the DNAME item with the value of the jsonobj.DNAME
        // an array was created in the object with the name row, so that is why you have to include row[0] to retrieve the data
        $s('P2_DNAME', jsonobj.row[0].DNAME);
    &lt;/script&gt;
    [/code]
    3.
    As the last step you need to create the event that fires the javascript
    code, since you've allready made the LOV, when it returns it will
    automatically fire an "onchange" event. So:
    * Go to the DEPTNO (or in your case objecttype_id) field and edit the "HTML Form Element Attributes" in the "Element Section" to:
    {code:java}onchange="lookupDname();" {code}
    This should fire the javascript, which fires the AJAX call, which fires
    the application process, that is returning a JSON string, which is then
    parsed in the javascript, and then used as a JSON object, to be
    referenced and used to set the item.... :^0
    Simple right! ?
    This will definitely solve your problem! Good luck.
    Greetings Rutger
    +P.S.+
    +You can also use the "eval()" function instead of the parseJSON method, but this is could be a security risk as it will execute whatever is passed into it!+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for

  • Printing Problem with Pro-100 and Photoshop

    This is my setup: using Mac Pro running Snow Leopard (10.6.8) & editing & printing from Photoshop CS 6. I have new Canon Pixma Pro-100 printer and set it up OK. First thing printed was a page from a document from MS Word on 8.5X11 plain paper - this

  • Slowing down the music in Logic Express

    Is it possible to slow down music without bringing down the pitch, like amazing slow downer does? Thanks, Frans Powerbook   Mac OS X (10.4.3)  

  • Change Soap Http Port name

    Hello, My 'Search' webservice is created from a Stateless EJB. I would like to change the Soap port from the default 'searchSoapHttpPort' to something else. How can this be done? I have tried changing the WSDL directly, but when the webservice is reg

  • CIF Error while transferring vendor

    We are facing CIF error while transferring vendor master to APO. The issue is in e-mail address of the vendor master. One way is to correct the e-mail addresses - one per line without semicolon at the end. But the issue list is very huge to get it co

  • Primary/standby question

    All, I've got a primary and standby 10g (10.2.0.4) on Windows 2003. I think/thought things were fine because when I execute SELECT SEQUENCE#, APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#; SELECT RECOVERY_MODE FROM V$ARCHIVE_DEST_STATUS WHERE DEST_I