Customer Portal

Get Involved. Join the Conversation.

Topic

    Dat N
    Changing report_id number dynamically
    Topic posted September 24, 2013 by Dat NRed Ribbon: 250+ Points 
    1110 Views, 22 Comments
    Title:
    Changing report_id number dynamically
    Content:

    Hello,

     

    I created a report_id = 120 to display in list2.php.  What I want is when someone click on the Search button (using search panel), I want the search function to use report_id = 130.  I am not sure if I make any sense, but if you know what I mean, please let me know how do I do it.

    Thank You

    Dat

    Code Snippet:

    Comment

    • luke davison

      One option is to change the reportId in a pre_report_get hook. Your hook code would need to look something like this:

      function preReportGet(&$hookData) {
          if ($hookData['data']['reportId'] === 120)
              $hookData['data']['reportId'] = 130;
      }
      
      

      You would need to subscribe this hook in the config/hooks.php file. Now whenever report 120 is ran on the server, it will instead run report 130.

    • Dat N

      Hello,

       

      It doesn't seem to work.  This is what I put in hooks.php

      function pre_report_get(&$hookData) {
          if ($hookData['data']['reportId'] == 120)
              $hookData['data']['reportId'] = 130;
      }
       

      Any idea ?

      Thank You,

    • luke davison

      The code I provided should go into a custom model and in config/hooks.php, it should point to the model/class and method. Take a look at the examples in the comments in that file for an example.

    • Dat N

      Yes I understood but the problem is that I don't have a class and method in my list2.php.  As you can see in the code below, when a user type in a criteria that they want to search (ie. name) and click on the Search button, I want to search in the report_id = 130. 

      This is my list2.php code:


      <rn:meta title="#rn:msg:FIND_ANS_HDG#" template="standard.php" clickstream="answer_list" use_profile_defaults="true"/>

      <rn:widget path="knowledgebase/RssIcon2" icon_path="" />
      <rn:container report_id="120" per_page="5" >
       <div id="rn_PageTitle" class="rn_AnswerList">
        <rn:condition is_spider="false">
         <div id="rn_SearchControls">
          <h1 class="rn_ScreenReaderOnly">#rn:msg:SEARCH_CMD#</h1>
          <form method="post" action="" onsubmit="return false" >
           <div class="rn_SearchInput">
            <rn:widget path="search/AdvancedSearchDialog" show_confirm_button_in_dialog="true"/>
            <rn:widget path="search/KeywordText2" label_text="#rn:msg:FIND_THE_ANSWER_TO_YOUR_QUESTION_CMD#" initial_focus="false"/>
           </div>
           <rn:widget path="search/SearchButton2" />
          </form>
          <rn:widget path="search/DisplaySearchFilters" />
         </div>
        </rn:condition>
       </div>

       <div id="rn_PageContent" class="rn_AnswerList">

        <div class="rn_Module">
         <h2>#rn:msg:MOST_POPULAR_ANSWERS_LBL#</h2>
         <font size="2"><rn:widget path="reports/ResultInfo2" add_params_to_url="p,c"/>
         <rn:widget path="knowledgebase/TopicWords2" />
         <rn:widget path="reports/Multiline2" />
         <rn:widget path="reports/Paginator" /></font>
        </div>
       </div>
      </rn:container>

    • luke davison

      No, you need to create a new model first, this doesn't go in your view. I'm assuming you're on v3. If you're on v2, the code will be slightly different, but the process is the same. For instance, you would create a new file: /dav/cp/customer/development/models/custom/ReportHook.php:

      <?php
      
      namespace Custom\Models;
      
      class ReportHook extends \RightNow\Models\Base
      {
          function __construct()
          {
              parent::__construct();
          }
      
          public function preReportGet(&$hookData)
          {
              if ($hookData['data']['reportId'] === 120) {
                  $hookData['data']['reportId'] = 130;
              }
          }
      }
      
      

      Then, in config/hooks.php, you configure the pre_report_get hook to call the ReportHook model's preReportGet method:

      
      $rnHooks['pre_report_get'][] = array(
          'class' => 'ReportHook',
          'function' => 'preReportGet',
          'filepath' => '',
      );
      
      
    • Dat N

      I get an error "Fatal error: Class 'RightNow\Models\Base' not found in /cgi-bin/esd.cfg/scripts/euf/application/development/source/models/custom/reporthook.php".  I don't have RightNow\Models\Base any where under RNW root folder.  Am I missing something ?

       

      Thanks

    • luke davison

      Based on the path to the file and the lack of namespaces, it means you're using v2 not v3. Your model code need to look different. Assuming the model uses this filename:

      models/custom/reporthook_model.php:

      Your model code would need to look something like this:

      <?php
      class Reporthook_model extends Model
      {
          function __construct()
          {
              parent::__construct();
          }
      
          public function preReportGet(&$hookData)
          {
              if ($hookData['data']['reportId'] === 120) {
                  $hookData['data']['reportId'] = 130;
              }
          }
      }
      
      

      Adjust the config/hooks.php to account for the different class name.

    • Dat N

      OK, so now I get "Hook Error: In hook pre_report_get, model does not exist at location models/custom/reporthook_model.php."   Where is the class model

       

       

    • Ernie Turner

      Did you create the model file with the contents Luke pasted above named reporthook_model.php under the 'development/models/custom' directory?

    • Matthew Workman

      Hi Dat,

      The code provided above should work but I would look at te sample code online it shows how to create a model and how to use hooks . I believe that is an example for what you are trying to do. If not I have the exact code you need as I am on v2 but I don't have a computer with me. Take a look at the examples for your version it will really help to debug your error.

       

      regards,

      Matthew

    • Dat N

      Hello Ernie,

       

      Yes I did create reporthook_model.php under the 'development/models/custom' directory with exact contents.

       

      Thanks

      -Dat

    • Dat N

      Since Reporthook_model class is extend the Model class, my guess is that it can't find the Model class in the path ? 

    • Dat N

      Hi Matthew,

       

      I will dig deeper into the problem, but if you get a chanced to pull our your code, could you send it to me ?

       

      Thanks for your help.

      Dat

    • luke davison

      What do you have in config/hooks.php?

    • Matthew Workman

      Hi Dat,

      I modified the "\euf\development\config\hooks.php" file to include

      $rnHooks['pre_report_get'] = array(
          'class' => 'report_kw',
          'function' => 'preReportGet',
          'filepath' => ''
      );
      

      Then created a new file called  "\euf\development\models\custom\report_kw.php"

      
      
      <?php
      class report_kw extends Model
      {
          function __construct()
          {
              parent::__construct();
              
          }
       
          function preReportGet($filters)
          {
              if ($filters['data']['reportId'] == 176)
              {
                  $filters['data']['reportId'] = 123456
              }
          }
      }
       

      For some reason using === didn't work so I had to use ==.

      Hope this helps,

      Matthew