duplicate cases search or sub panel

Hi, We are using the cases module and the cases subject is created by concatenating a few fields within the case. The result of this, if two cases have the same subject, it will mean that they are related to each other.

can anyone think of a way I could have a link which shows all the related cases (cases with the same subject) or even better a sub panel, with all the cases with the same subject.

Any help would be great.

SuiteCRM 7.10.9

One approach would be to actually create that relationship between the records. You could do it in an after-save Logic hook: when the subject is edited, check if there are other Cases with the same subject, and add a relationship in the database. Be careful with possible loops or repeated addition of relationships.

The other way would be to just display those connections, without actually creating them in the database. you could create a new custom subpanel and edit the SQL query to define what it shows, something like this:
https://suitecrm.com/suitecrm/forum/suitecrm-7-0-discussion/19222-subpanels-cases#66668

1 Like

Thanks. Thus looks like a good starting point.

Hi, I have tried to customize your code provided here: https://suitecrm.com/suitecrm/forum/suitecrm-7-0-discussion/19222-subpanels-cases#66668 with the following:

custom/Extension/modules/Cases/Ext/Layoutdefs/related_cases.php


<?php

$layout_defs["Cases"]["subpanel_setup"]['related_cases'] = array(
    'order' => 1,
    'module' => 'Cases',
    'sort_order' => 'asc',
    'sort_by' => 'name',
    'subpanel_name' => 'default',
    'get_subpanel_data' => 'function:getRelatedCasesQueryData',
    'function_parameters' => array(
    'import_function_file' => 'custom/modules/Cases/GetCasesSubpanelData.php',
    'link' => 'related_cases'
    ),
    'add_subpanel_data' => 'case_id',
    'title_key' => 'LBL_LEADS_SUBPANEL_TITLE',
    'top_buttons' => array(),
    );

custom/modules/Cases/GetCasesSubpanelData.php


<?php
require_once 'custom/modules/Cases/BuildCasesSubpanelQueryService.php';

function getRelatedCasesQueryData($param){
    $service = new BuildCasesSubpanelQueryService();
    return $service->buildQuery($param);
}

/custom/modules/Cases/BuildCasesSubpanelQueryService.php


<?php

class BuildCasesSubpanelQueryService
{

    public function __construct()
    {}

    public function buildQuery($param)
    {
        global $app;
        $controller = $app->controller;
        $bean = $controller->bean;
        $query = "
            SELECT *
            FROM cases
            WHERE cases.name = '$bean->name'
              AND leads.deleted = 0
               ";
        return $query;
    }
}

When access a Cases i get the following error on the apache log


[Thu Oct 04 15:48:03.405591 2018] [:error] [pid 1281] [client 172.16.1.9:24406] script '/var/www/html/cache/index.php' not found or unable to stat, referer: http://172.16.1.141/cache/themes/SuiteP/css/Dawn/style.css?v=laZZs6_8zG339cBR3gnuBA

And this screen

Any Suggestions

I have also tried achieving this by using this: http://urdhva-tech.com/blogs/add-custom-subpanel-in-accounts-module

My files look like this:

/var/www/html/custom/Extension/modules/Cases/Ext/Layoutdefs/RelatedCases.php


<?php 
$layout_defs['Cases']['subpanel_setup']['related_cases'] =
        array('order' => 49,
            'module' => 'Cases',
            'subpanel_name' => 'ForCases',
            'get_subpanel_data' => 'function:get_related_cases',
            'generate_select' => true,
            'title_key' => 'LBL_RELATED_CASES',
            'top_buttons' => array(),
            'function_parameters' => array(
                'import_function_file' => 'custom/modules/Cases/customRelatedSubpanel.php',
                'Case_Name' => $this->_focus->name,
                'return_as_array' => 'true'
            ),
);

/var/www/html/custom/modules/Cases/customRelatedSubpanel.php


<?php 
function get_related_cases($params) {

	$args = func_get_args();
    $opportunitiesSalesStage = $args[0]['sales_stage'];
    $CaseName = $args[0]['Case_Name'];
	
    $return_array['select'] = " SELECT cases.*";
    $return_array['from'] = " FROM cases ";
    $return_array['where'] = " WHERE cases.deleted = '0' AND cases.name = '" . $CaseName . "'";
    $return_array['join'] = '';
    $return_array['join_tables'] = '';
    return $return_array;
	
}

The cases record opens, but when trying to open the new sub panel, I get gif representing it is thinking and this error message on the apache log


[Thu Oct 04 15:18:17.880725 2018] [:error] [pid 1282] [client 172.16.1.9:20825] PHP Notice:  Trying to get property of non-object in /var/www/html/include/SubPanel/SubPanel.php on line 387, referer: http://172.16.1.141/index.php?action=ajaxui
[Thu Oct 04 15:18:17.884436 2018] [:error] [pid 1282] [client 172.16.1.9:20825] PHP Notice:  Trying to get property of non-object in /var/www/html/include/SubPanel/SubPanel.php on line 172, referer: http://172.16.1.141/index.php?action=ajaxui
[Thu Oct 04 15:18:17.884616 2018] [:error] [pid 1282] [client 172.16.1.9:20825] PHP Notice:  Trying to get property of non-object in /var/www/html/include/SubPanel/SubPanel.php on line 437, referer: http://172.16.1.141/index.php?action=ajaxui
[Thu Oct 04 15:18:17.884689 2018] [:error] [pid 1282] [client 172.16.1.9:20825] PHP Notice:  Trying to get property of non-object in /var/www/html/include/SubPanel/SubPanel.php on line 423, referer: http://172.16.1.141/index.php?action=ajaxui
[Thu Oct 04 15:18:17.884743 2018] [:error] [pid 1282] [client 172.16.1.9:20825] PHP Notice:  Trying to get property of non-object in /var/www/html/include/ListView/ListViewSubPanel.php on line 135, referer: http://172.16.1.141/index.php?action=ajaxui

[Thu Oct 04 15:18:17.885016 2018] [:error] [pid 1282] [client 172.16.1.9:20825] PHP Fatal error:  Uncaught Error: Call to a member function isCollection() on boolean in /var/www/html/data/SugarBean.php:968\nStack trace:\n
#0 /var/www/html/include/ListView/ListView.php(1132): SugarBean::get_union_related_list(Object(aCase), 'id', 'asc', '', '', -1, 10, '', false)\n
#1 /var/www/html/include/ListView/ListViewSubPanel.php(142): ListView->processUnionBeans(Object(aCase), false, '_CELL')\n
#2 /var/www/html/include/SubPanel/SubPanel.php(220): ListViewSubPanel->process_dynamic_listview('Cases', Object(aCase), false)\n
#3 /var/www/html/include/SubPanel/SubPanel.php(231): SubPanel->ProcessSubPanelListView('include/SubPane...', Array)\n
#4 /var/www/html/include/SubPanel/SubPanelViewer.php(95): SubPanel->display()\n
#5 /var/www/html/include/MVC/Controller/SugarController.php(1087): require_once('/var/www/html/i...')\n
#6 /var/www/html/include/MVC/Controller/SugarController.php(468): SugarController->handleActionMaps()\n
#7 /var/www/html/include/MVC/Controller/SugarController.php(373): SugarController->process()\n
#8 /var/www/html/inclu in /var/www/html/data/SugarBean.php on line 968, referer: http://172.16.1.141/index.php?action=ajaxui

If anyone could help on either of these methods or point me in another direction Any help would be greatly appreciated .

Always check both php_errors.log and suitecrm.log side by side. You have some previous error to that, because this line

$isCollection = $subpanel_def->isCollection();

expects subpanel_def to be a class, and instead it’s a boolean (we can bet it’s “false” because something failed in the class creation).

Look for errors earlier in both logs.

Thank you. The suiteCRM log was the key here!

The error was in the SQL statement.

AND leads.deleted = 0 should be AND cases.deleted = 0

I am glad you got it working! :slight_smile: