How to create a subpanel in sugarcrm 7.6 in Accounts module.

Hi

   I want to create a subpanel,I have created an custom field-relatedaccount_c(related to accounts module)field in the Calls/Meetings/Tasks modules.This field appears only when the Parent Type="Projects" for the calls/Meetings/Tasks.So in the accounts module i want a Project Activities subpanel in which we can see all the list of calls/meetings/tasks whose parent type is Projects and  relatedaccount_c.Shijin Krishna Gustav Lindström Ajay Kumar

  • Hi Gustav

         Currently i am working on sugarcrm 7.6

         I have tried

    /<>/custom/Extension/modules/Accounts/Ext/Layoutdefs/test_subpanel.php

    <?php

    $layout_defs['Accounts']['subpanel_setup']['relatedaccount_c'] =

            array(order => 49,

                'module' => 'Calls',

                'subpanel_name' => 'Project Activities',

                'get_subpanel_data' => 'function:get_related_accounts',

                'generate_select' => true,

                'title_key' => 'LBL_RELATEDACCOUNT',

                'top_buttons' => array(),

                'function_parameters' => array(

                    'import_function_file' => 'custom/modules/Accounts/customRelatedAccountsSubpanel.php',

                    'account_id' => $this->_focus->id,

                    'return_as_array' => true

                ),

    );

    /<>/custom/modules/Accounts/customRelatedAccountsSubpanel.php

    <?php

    function get_related_accounts($params) {

        $args = func_get_args();

        $accountId = $args[0]['account_id'];

        $return_array['select'] = "SELECT c.name";

        $return_array['from'] =   "FROM calls c";

        $return_array['where'] =  "WHERE a.id ='".$accountId."'";

        $return_array['join'] =   "LEFT JOIN calls_cstm cc ON c.id=cc.id_c LEFT JOIN accounts a on a.id=cc.account_id_c";

        $return_array['join_tables'] = ”;

        return $return_array;

    }

    /<>/custom/Extension/modules/Accounts/Ext/Language/en_us.lang.php

    $mod_strings['LBL_RELATEDACCOUNT'] = 'Project Activities';

    But i was unable to get a subpanel

  • Sorry the second link is for sugar 6. You should look at the first one, I've tried it and it worked for me. It looks like you followed the seconj one from the developer blog and it doesnt work in sugar 7.x

  • Hi Gustav

        As a start up can you please update me something simple.For example like creating the calls subpanel in Accounts or anything simple.

  • Have you tied the package? Installed it? Does it work? You change the content of getCustomJoin function to get another result.

  • public function getRelatedModuleName()

      {

      return 'Calls'; //Here you change linked module

      }

    And in getCustomJoin you change the result

        protected function getCustomJoin($params = array())

        {

      $GLOBALS['log']->fatal('Linkcalls getCustomJoin');

            $bean_id = $this->db->quoted($this->focus->id);

            $sql = " INNER JOIN(";

            $sql .= "SELECT calls_result.id FROM calls as calls_result inner join contacts as contacts_c on calls_result.parent_id = contacts_c.id left join accounts_contacts on contacts_c.id = accounts_contacts.contact_id Where calls_result.parent_type = 'Contacts' and accounts_contacts.account_id = {$bean_id}";

      //$sql .= "SELECT id FROM calls where id = '566cf15c-0fcf-1f5d-86f5-542bb8eda451'"; // This is essentially a select statement that will return a set of ids that you can match with the existing sugar_query

            $sql .= ") calls_result ON calls_result.id = calls.id";

            return $sql;

      //return "";

        }

  • Hi Gustav

        I was able to get the subpanel in the accounts module.

    This was working fine

    protected function getCustomJoin($params = array())

        {

      $GLOBALS['log']->fatal('Linkcalls getCustomJoin');

            $bean_id = $this->db->quoted($this->focus->id);

            $sql = " INNER JOIN(";

            $sql .= "SELECT calls_result.id FROM calls as calls_result

    LEFT JOIN calls_cstm cc ON calls_result.id=cc.id_c

    LEFT JOIN accounts a ON a.id=cc.account_id_c WHERE a.id={$bean_id}";

      //$sql .= "SELECT id FROM calls where id = '566cf15c-0fcf-1f5d-86f5-542bb8eda451'"; // This is essentially a select statement that will return a set of ids that you can match with the existing sugar_query

            $sql .= ") calls_result ON calls_result.id = calls.id";

            return $sql;

      //return "";

        }

    Actually my requirement is

    I have created an custom field-relatedaccount_c(related to accounts module)field in the Calls/Meetings/Tasks modules.This field appears only when the Parent Type="Projects" for the calls/Meetings/Tasks.So in the accounts module i want a Project Activities subpanel in which we can see all the list of calls/meetings/tasks whose parent type is Projects and  relatedaccount_c

    So I want to insert the  query like below  to the getCustomJoin() So that i will get all the records of the calls,meetings and tasks related to the Accounts and parent type is projects in to the subpanel we created

    SELECT c.id FROM calls c

    LEFT JOIN calls_cstm cc ON c.id=cc.id_c AND c.deleted=0

    LEFT JOIN accounts a ON a.id=cc.account_id_c WHERE a.parent_type='P_Projects' AND a.id='4e5da5a4-9281-ab68-9407-5617aec95927'

    UNION ALL

    SELECT m.id FROM meetings m

    LEFT JOIN meetings_cstm mm ON m.id=mm.id_c AND m.deleted=0

    LEFT JOIN accounts ac ON ac.id=mm.account_id_c WHERE m.parent_type='P_Projects' AND ac.id='4e5da5a4-9281-ab68-9407-5617aec95927'

    UNION ALL

    SELECT t.id FROM tasks t

    LEFT JOIN tasks_cstm tt ON t.id=tt.id_c AND t.deleted=0

    LEFT JOIN accounts acc ON acc.id=tt.account_id_c WHERE t.parent_type='P_Projects' AND acc.id='4e5da5a4-9281-ab68-9407-5617aec95927'

  • Hi Gustav

         I want the subpanel so that it contains records from Tasks,Meetings and Calls.

    I have tried

    custom/Extension/modules/Accounts/Ext/Vardefs/your_field_name.php

    <?php

    $dictionary["Account"]["fields"]["your_field_name"] = array(

        'name' => 'all_calls',

        'type' => 'link',

        'link_file' => 'custom/modules/Accounts/LinkCalls.php',

        'link_class' => 'YourNewLink',

        'source' => 'non-db',

        'vname' => 'LBL_NEW_LINK',

        'module' => 'Calls',

        'link_type' => 'many',

        'relationship' => '',

    );

    $dictionary["Account"]["fields"]["your_field_name"] = array(

        'name' => 'all_calls',

        'type' => 'link',

        'link_file' => 'custom/modules/Accounts/LinkCalls.php',

        'link_class' => 'YourNewLink',

        'source' => 'non-db',

        'vname' => 'LBL_NEW_LINK',

        'module' => 'Meetings',

        'link_type' => 'many',

        'relationship' => '',

    );

    $dictionary["Account"]["fields"]["your_field_name"] = array(

        'name' => 'all_calls',

        'type' => 'link',

        'link_file' => 'custom/modules/Accounts/LinkCalls.php',

        'link_class' => 'YourNewLink',

        'source' => 'non-db',

        'vname' => 'LBL_NEW_LINK',

        'module' => 'Tasks',

        'link_type' => 'many',

        'relationship' => '',

    );

    as i need the record from the three modules records in to the same subpanel.But currently it is not working as we require