6 Replies Latest reply: Jan 2, 2013 7:33 AM by evrm RSS

    Passing an item value to a embedded report with $a_report

    rlebret
      Hi,

      Still one issue for this end of year...
      APEX : 3.2.1 + apex listener
      OS : Linux

      I have an interactive report. When I select a row I get an id that sets a item P83_ID_OPERATION within a javascript.
           function table_object(pId){   
                this.id = pId;   
                this.start_record = 1;      //optional   
                this.num_record = 5;        //optional   
                this.interval = false;   
                this.refresh = function(pTime){   
                if(my_report.interval){clearInterval(my_report.interval)}   
                if(!!pTime){
                     my_report.interval = setInterval(function(){my_report.call_refresh()},pTime * 1000);}   
                }   
                this.call_refresh = function(){
                     $a_report(this.id.substring(1),this.id.start_record,this.num_record);
                }   
           }
      
           function highlight(r)
           {
           
           var i = r.parentNode.parentNode.rowIndex;
           var table = r.parentNode.parentNode.parentNode.parentNode
           var id_ope = table.rows.cells[1].innerText;
           
           // set PXX_ID_OPERATION item
           $x('P83_ID_OPERATION').value=id_ope;
           
           my_report1.call_refresh();
           my_report2.call_refresh();     

           return true;
           }
      This works (almost) fine. When I select a row, the variable P83_ID_OPERATION is correctly set but the 2 reports are not refreshed.
      I changed the request behing the report my_report1 to debug it with a very basic select :
      select
      to_char(sysdate,'DD/MM/YYYY HH24:MI:SS') mydate, :P83_ID_OPERATION myid
      from dual
      I constat that the report is really refreshed by the call_refresh function (the date is changed at every call) but the P83_ID_OPERATION item is not correctly passed during the recall (I keep a previous value !). Where is my mistake ? Is my P83_ID_OPERATION only local ? Is there a way to decalre it as global and  share it with all the dependent embedded report ?
      
      Thank in advance and happy new year...
      
      Edited by: 975489 on Dec 31, 2012 5:32 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
        • 1. Re: Passing an item value to a embedded report with $a_report
          evrm
          Hi,

          the value of the item P83_ID_OPERATION is indeed local.
          You need to use an Ajax call to set the value in session state.
          This article http://www.packtpub.com/article/ajax-implementation-apex is a good intro to Ajax in Apex 3 and above.
          Based on this article I've put some example code below

          After you set the local value of the item, you need to execute the Ajax call and on return refresh your reports.
          Create an application process demo_code to set the value of the item.
          begin
             :P83_ID_OPERATION := apex_application.g_x01;
          end;
          Then call this process in the following Ajax call
          var ajaxReq = new htmldb_Get(null, $v('pFlowId'), 'APPLICATION_PROCESS=demo_code', $v('pFlowStepId'));
          ajaxReq.addParam('x01',$v('P83_ID_OPERATION'));
          ajaxReq.GetAsync(refresh_reports);
          ajaxReq = null;
          regards,
          Erik-jan
          • 2. Re: Passing an item value to a embedded report with $a_report
            rlebret
            Hi Erik

            Indeed it works... Thank a lot for the article that explained me ajax life (dura lex sed lex !).
            A quick update however...

            I will need to set many page items in different portions of code/pages.
            Is there a way to use a generic very simple application process for all the initialisation instead of declaring the variable in the code... Basically I just need to initialise a page item with a value...

            I tried...
            BEGIN
            :apex_application.g_x01:=apex_application.g_x02;;
            and
            ajaxReq.addParam('x01','P83_ID_OPERATION');
            ajaxReq.addParam('x02',$v('P83_ID_OPERATION'));
            ... but it doesn't work. Any idea for a generic declaration ?
            • 3. Re: Passing an item value to a embedded report with $a_report
              VC
              rlebret wrote:
              Hi Erik

              Indeed it works... Thank a lot for the article that explained me ajax life (dura lex sed lex !).
              A quick update however...

              I will need to set many page items in different portions of code/pages.
              Is there a way to use a generic very simple application process for all the initialisation instead of declaring the variable in the code... Basically I just need to initialise a page item with a value...

              I tried...
              BEGIN
              :apex_application.g_x01:=apex_application.g_x02;;
              First of all this won't work because syntactically it is wrong. +(two ; at the end)+
              It will not work even if you fix that issue.
              and
              ajaxReq.addParam('x01','P83_ID_OPERATION');
              ajaxReq.addParam('x02',$v('P83_ID_OPERATION'));
              ... but it doesn't work. Any idea for a generic declaration ?
              You might try this
              BEGIN
                  APEX_UTIL.SET_SESSION_STATE(apex_application.g_x01,apex_application.g_x02);
              END;
              See SET_SESSION_STATE Procedure

              Thanks,
              Vikram
              • 4. Re: Passing an item value to a embedded report with $a_report
                rlebret
                great...
                That exactly what I was looking for...
                • 5. Re: Passing an item value to a embedded report with $a_report
                  rlebret
                  Hi Erik-jan


                  thank you, your answer was correctly and Vikram'one too.
                  I wanted to mark both answers as correct,butt seems i can not.
                  Can you please make me a "silly" reply for I try giving you 5 more points.

                  Regards

                  Edited by: rlebret on Jan 2, 2013 4:37 AM
                  • 6. Re: Passing an item value to a embedded report with $a_report
                    evrm
                    Hi,

                    thanks a lot and great I could help you out with your problem.
                    Happy Apex coding in 2013.

                    regards,
                    Erik-jan