This is a public Forum  publicRSS

Topic

    Nisar Ahmed
    View organization's incidents along with own incidentsAnswered
    Topic posted August 10, 2018 by Nisar AhmedMaster, last edited August 13, 2018 
    26 Views, 2 Comments
    Title:
    View organization's incidents along with own incidents
    Content:

    I'm using a "pre_report_get" hook and trying to apply a filter that accepts multiple values. The problem is that I'm not able to figure out the correct format in which the filter values need to be passed. The code I'm using as follows:

    function applyInstituteFilter(&$hookData)
        {
            $reportID = $hookData['data']['reportId'];
            
            if($hookData['data']['reportId'] == 100520)
            {
                $insFilter = $this->CI->model('Report')->getFilterByName($reportID, 'ins_ids')->result;
                if(!$hookData['data']['filters']['ins_ids']){
                        $ins_filter = $this->CI->model('Report')->createSearchFilter($reportID, $insFilter['name'], $insFilter['fltr_id'], 1, 'custom', $insFilter['oper_id'])->result;                         
                        $hookData['data']['filters']['ins_ids'] = $ins_filter;
                }
                $hookData['data']['filters']['ins_ids']->filters->data = array(2,1,4); // 2,1,4 are the possible values         
                
                
            }
        }
    

    I'm also a bit confused with the 4th and 5th parameter of the "createSearchFilter" function. As I understand, I could pass anything in there, right?

    In either case, I tried with:

    $hookData['data']['filters']['ins_ids']->filters->data = array(2,1,4); // fails
    $hookData['data']['filters']['ins_ids']->filters->data = array('2,1,4'); // fails, comma separated
    $hookData['data']['filters']['ins_ids']->filters->data = array('2;1;4'); // fails, semicolon seperated
    $hookData['data']['filters']['ins_ids']->filters->data = array('2|1|4'); // fails, pipe seperated
    

    Here is the filter definition (which works fine when run in the agent desktop:

    Version:
    3.7

    Best Answer

    Nisar Ahmed

    Well, I managed to remove it. The trick was hooking onto the "pre_report_get_data" hook where the search filters are applied.

    function removeInBuiltContactFilter(&$hookData)
    {        
        if($hookData['data']['reportId'] == 100521)
        {
            $searchArgs = $hookData['data']['queryArguments']['search_args']; // other parameters that are about to be set on the report
            foreach($searchArgs as $searchKey => $meta)
            {                
                if($meta['name'] == 'incidents.c_id') // this means that the report will have the logged in contact id filter set
                {                    
                    unset($hookData['data']['queryArguments']['search_args'][$searchKey]);
                    break;
                }
             }            
         }
    }
    

    Answer

     

    • Nisar Ahmed

      So, as it turns out. Using "array(1,2,24)" is the correct way (I tested it with a sample report) but in this case it was failing because CP was adding the contact filter internally so as to prevent unauthorized access to incidents. This internal filter was also overriding my report definition which said "ContactID = <something> OR OrgsID IN <list>".

      The use case is such that I want the logged in user to view incidents belonging to his organization but with a special case that he/she might be associated with multiple organizations.

      Is there a way to bypass the CP check that prevents the logged in contact to not view incidents that are not linked to his/her contact record? For the record, I'm using the report in the "reports/Grid" widget.

    • Nisar Ahmed

      Well, I managed to remove it. The trick was hooking onto the "pre_report_get_data" hook where the search filters are applied.

      function removeInBuiltContactFilter(&$hookData)
      {        
          if($hookData['data']['reportId'] == 100521)
          {
              $searchArgs = $hookData['data']['queryArguments']['search_args']; // other parameters that are about to be set on the report
              foreach($searchArgs as $searchKey => $meta)
              {                
                  if($meta['name'] == 'incidents.c_id') // this means that the report will have the logged in contact id filter set
                  {                    
                      unset($hookData['data']['queryArguments']['search_args'][$searchKey]);
                      break;
                  }
               }            
           }
      }