8 Replies Latest reply on Oct 5, 2007 6:08 AM by 135285

    Dynamically change Report Template

    49708
      Is it possible to dynamically change the Report Template? WebDB used to provide option if user want output in HTML /Excel/ASCII format. I am looking to simulate that (with only HTML and CSV output).
      Is there a way I can set the Report Template to "Template 13: Standard, Alternating row colors" or to "export:CSV" based upon a user selection?

      Thanks,
      Jay
        • 1. Re: Dynamically change Report Template
          Arie Geller
          Hello,

          In the report attribute page, you have a section called “Report Export”. If you’ll set the “Enable CSV output” field to yes, it will add a CSV download link at the end of your on-screen report. You should set the report template to be the one that will give you the HTML look you want.

          Regards,
          Arie.
          • 2. Re: Dynamically change Report Template
            49708
            Arie,
            Thanks. I know that option and it's already enabled in my reports. What I want to do is decide whether to display the report or directly put into the CSV file based on the user parameter. If the user selects HTML then it shows on the screen using the Standard 13 Alteranting Row colors template. If the user select CSV then the output directly goes into Excel without showing the HTML output.
            I want to know if that option can be set with some built-in.

            Thanks,
            Jay
            • 3. Re: Dynamically change Report Template
              Arie Geller
              Hello Jay,

              OK, I see now what you are trying to do.

              You can’t change the report template on the fly, but you can create another page with the CSV template, and branch to it according to user choice.

              On the first page you need to add a select list (or radio item) to allow the user to enter his/her choice. The report on this page should be condition by this item value set to the proper value. If, on the other hand, the user select the CSV option, he/she will redirect to the proper page, which will include only the report region, with the CSV template, and an unconditional branch back to the calling page.

              On the select item, you can use the following event code:
              onchange="if (this.value == 2) { redirect('f?p=&APP_ID.:22:&SESSION.');} else { doSubmit('Go')};"
              This code assumes that ‘2’ is the return value if the user chooses the CSV option, and that report is on page 22.

              Regards,
              Arie.
              • 4. Re: Dynamically change Report Template
                49708
                Arie,
                Thanks for the detail reply.
                I will have the query in two places then I guess.

                Jay
                • 5. Re: Dynamically change Report Template
                  Arie Geller
                  Hello Jay,

                  >> I will have the query in two places then I guess.

                  If you want to keep it really simple, the answer is yes.

                  If you are running APEX 3.0.1, you can use the new report queries. This feature allow you to set an item on page, to let the user choose the report format. However, using this feature require you to configure a print server. You can read more about it in the following - http://www.oracle.com/technology/products/database/application_express/html/configure_printing.html .

                  Regards,
                  Arie.
                  • 6. Re: Dynamically change Report Template
                    135285
                    Jay,

                    I don't think that you have to duplicate your query. Just use the same URL the CSV export link uses the request the file. Eg the URL looks like http://apex.oracle.com/pls/otn/f?p=41928:5:221572713051000:FLOW_EXCEL_OUTPUT_R7188106818717186923_en-us where FLOW_EXCEL_OUTPUT_R7188106818717186923_en-us is used as request and which triggers the CSV output.

                    1) Use the "Static ID" property of your report region and enter eg. MyReport
                    2) On your search page create a hidden item P5_REPORT_REGION_ID, set "Source Type" to "SQL Query" and use the following query to get the internal region id of APEX.
                    SELECT REGION_ID
                      FROM APEX_APPLICATION_PAGE_REGIONS
                     WHERE APPLICATION_ID = :APP_ID
                       AND PAGE_ID        = 5 -- replace that with the page number where your report is
                       AND STATIC_ID      = 'MyReport'
                    3) Create a "Submit Page and Redirect to URL" button for CSV output where you enter the page number of your report
                    4) Go into the properties of the button and set "Request" to
                    FLOW_EXCEL_OUTPUT_R&P6_REPORT_REGION_ID._en-us
                    -> At runtime the placeholder is replaced with the real region id
                    5) Create a "Submit Page and Redirect to URL" button for html output where you just enter the page number of your report.

                    That's it. See http://apex.oracle.com/pls/otn/f?p=41928:6 for an example.

                    Using that technique you don't have to duplicate your report.

                    Patrick
                    ----------------------------------------------------------------------------------------------------
                    My APEX Blog: http://inside-apex.blogspot.com
                    The ApexLib Framework: http://apexlib.sourceforge.net
                    The APEX Builder Plugin: http://sourceforge.net/projects/apexplugin/
                    • 7. Re: Dynamically change Report Template
                      Arie Geller
                      Hello Patrick,

                      >> Using that technique you don't have to duplicate your report.

                      For standard CSV files, this is indeed a very smart and maintainable solution.

                      I can see they finally set your icon right, so congratulation (one more time).

                      Regards,
                      Arie.
                      • 8. Re: Dynamically change Report Template
                        135285
                        Thanks Arie!

                        Yes it took some time! :-)

                        Patrick
                        ----------------------------------------------------------------------------------------------------
                        My APEX Blog: http://inside-apex.blogspot.com
                        The ApexLib Framework: http://apexlib.sourceforge.net
                        The APEX Builder Plugin: http://sourceforge.net/projects/apexplugin/