Customer Portal

Get Involved. Join the Conversation.

Topic

    Baljeet Singh
    Set Dynamic Filter in CPAnswered
    Topic posted September 13, 2019 by Baljeet SinghRed Ribbon: 250+ Points 
    24 Views, 3 Comments
    Title:
    Set Dynamic Filter in CP
    Summary:
    How to set dynamic filter in custom report in CP
    Content:

    Hi,

    We have business requirement to set dynamic filter in custom report in CP. The custom report has custom object field i.e CustomObject.FieldName as Run time filter. We need to pass dynamic value to report filter when customer log in into CP. We are able to get this field value in CP but unable to display result based on this field value. Here are the steps I did

    1. I have created run time filter in custom report i.e Master. PFA the screenshot

    2. In question list page, I used custom widget with hard coded static filter value

    <rn:widget path="custom/Report/ReportGrid_v2"    report_id="100268"  static_filter="Master=474"/>

    3. In this custom widget controller.php

     

    //Set Dynmaic Filter For Master Store
     $getFilter = $this->CI->model('Report')->getFilterByName($this->data['attrs']['report_id'], 'Master');
    $masterFilter = $getFilter->result;
    $widgetArg = $masterFilter['name'];
    $filters[$widgetArg]->filters->rnSearchType = 'custom';
    $filters[$widgetArg]->filters->fltr_id = $masterFilter['fltr_id'];
    $filters[$widgetArg]->filters->oper_id = $masterFilter['oper_id'];
    $filters[$widgetArg]->filters->name    = $masterFilter['name'];
    $filters[$widgetArg]->filters->data = 474;        

     

    It did not work for dynamic filter and could not get the result. It is showing all incident but our requirement is to display only incident based on dynamic filter value i.e. Master = 474

    I also tried using hooks with custom model i.e. custom/model.php

     
    $filters['custom1']->filters->fltr_id = 1;
    $filters['custom1']->filters->report_id = '100268';
    $filters['custom1']->filters->oper_id = 1;
    $filters['custom1']->filters->data = 474;
    $filters['custom1']->filters->rnSearchType = 'custom';

    Still no luck. It seems like I am missing something and custom filter is not getting configure properly. Does anyone has an idea how to fix this issue.

    Appreciate your support

    Baljeet Singh

     

    Version:
    Oracle Service Cloud 19 A
    Image:
    Code Snippet:

    Best Comment

    Baljeet Singh

    Hi

    I am able to solve this issue. Here are the steps anyone need to follow

    1. Create hook 

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

     

    2. In model ans_model.php

    function AddFilter(&$data)
    {
          
       if($data['data']['reportId']==100026)
       {
             
                     $contact = null;
                   $CI = &get_instance();
                   $cid = $CI->session->getProfileData('c_id');
                   if (!Framework::isLoggedIn() || !Framework::isValidID($cid)) {
                                    return false;
                   } else{
                             $contact = Connect\Contact::fetch($cid);
                   } 
     
                $masterStore = $contact->Organization->CustomFields->CO->MasterStore->Meaning;
               $data['data']['queryArguments']['search_args']['search_field3']['val'] = $masterStore;
             $data['data']['queryArguments']['search_args']['search_field3']['name'] = 'CO$MasterStores.Meaning';
             $data['data']['queryArguments']['search_args']['search_field3']['oper'] = OPER_LIST;
       }
    }
     
    3. In custom widget controller.php file , No customization needed and leave it as it is 
     
      Use standard Report model 
       $results = $this->CI->model('Report')->getDataHTML($this->data['attrs']['report_id'], $reportToken, $filters, $format)->result;
     
    4. No need to do anything in view.php. 
     
    4. You will able to get desire result
     
    I hope this will help everyone to fix issue (How to set dynamic filter value in CP)
     
    Thanks!!
    Baljeet Singh

    Comment

     

    • Daniel Rocha

      The field name you are using must match the exact name you gave to the filter in the console. If it's the same and it's still not working you could try set it directly in the view like this:

       

      <?php

      $idMaster = \RightNow\Utils\Url::getParameter('master'); // just as example, the markup below is the important part

      ?>

      <rn:widget path="custom/Report/ReportGrid_v2"  report_id="100268"  static_filter="Master=#rn:php:$idMaster#"/>

    • Baljeet Singh

      Thanks Deniel for your reply

      I have already tried hard coded value in view.php but it is not working

      <rn:widget path="custom/Report/ReportGrid_v2"  report_id="100268"  static_filter="Master=474"/>

      I was able to get these value in controller.php file but unable to get desire result based on this value. Here is an array I get when I debugged it

      Array
      (
          [Master] => stdClass Object
              (
                  [filters] => stdClass Object
                      (
                          [rnSearchType] => custom
                          [searchName] => Master
                          [report_id] => 100268
                          [data] => 474
                          [oper_id] => 1
                          [fltr_id] => 1
                      )

              )

      )

       

      After setting dynamic filter, I am not able to get result

       

      //Set Dynmaic Filter For Master Store
              $getFilter = $this->CI->model('Report')->getFilterByName($this->data['attrs']['report_id'], 'Master');
              $masterFilter = $getFilter->result;
              $widgetArg = $masterFilter['name'];
              $filters[$widgetArg]->filters->rnSearchType = 'custom';
              $filters[$widgetArg]->filters->fltr_id = $masterFilter['fltr_id'];
              $filters[$widgetArg]->filters->oper_id = $masterFilter['oper_id'];
              $filters[$widgetArg]->filters->name    = $masterFilter['name'];
              $filters[$widgetArg]->filters->data = 474;           
              
              $results = $this->CI->model('Report')->getDataHTML($this->data['attrs']['report_id'], $reportToken, $filters, $format)->result;
              

          It display all result but we need to get result based on filter value i.e. 474

       

      Thanks!!

      Baljeet 

    • Baljeet Singh

      Hi

      I am able to solve this issue. Here are the steps anyone need to follow

      1. Create hook 

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

       

      2. In model ans_model.php

      function AddFilter(&$data)
      {
            
         if($data['data']['reportId']==100026)
         {
               
                       $contact = null;
                     $CI = &get_instance();
                     $cid = $CI->session->getProfileData('c_id');
                     if (!Framework::isLoggedIn() || !Framework::isValidID($cid)) {
                                      return false;
                     } else{
                               $contact = Connect\Contact::fetch($cid);
                     } 
       
                  $masterStore = $contact->Organization->CustomFields->CO->MasterStore->Meaning;
                 $data['data']['queryArguments']['search_args']['search_field3']['val'] = $masterStore;
               $data['data']['queryArguments']['search_args']['search_field3']['name'] = 'CO$MasterStores.Meaning';
               $data['data']['queryArguments']['search_args']['search_field3']['oper'] = OPER_LIST;
         }
      }
       
      3. In custom widget controller.php file , No customization needed and leave it as it is 
       
        Use standard Report model 
         $results = $this->CI->model('Report')->getDataHTML($this->data['attrs']['report_id'], $reportToken, $filters, $format)->result;
       
      4. No need to do anything in view.php. 
       
      4. You will able to get desire result
       
      I hope this will help everyone to fix issue (How to set dynamic filter value in CP)
       
      Thanks!!
      Baljeet Singh