Hachim IDRISSI
Hachim IDRISSI

Reputation: 217

Security Group subpanel doesn't exist for quotes, contrats, invoices, and events modules

I am using suiteCRM 7.7.4 (Sugar Version 6.5.24) and I need to use Security group subpanel in quotes, contracts, invoices and events modules, but for some reasons I can't find it ! I did some researches and I found that this subpanel doesn't appear by default for custom modules.. some developers recommand to do not use the studio to build this kind of relationship, because simply it will not work ! for paid version of sugarCRM they say that there was a tool called "hookup tool" that creates the relationship for you... but As I am using a free version I can't use it !

Do you have any idea ?

Thank you very much !

Upvotes: 1

Views: 511

Answers (2)

Amitesh Kumar
Amitesh Kumar

Reputation: 3079

follow this following steps:

1. Go to Admin
2. Go to studio
3. Select your module where you want subpanel like "invoices"
4. Go to relationship
5. Add 1 to many relationship with Security group module.
6. Now repair rebuild you will find the subapnel in invoice module.

When you create 1 to many relationship with any module it will create the subpanel.

IF its not working then go for custom subpanel.

Refer this linnk I put code from same link it worked for me

This tutorial should hopefully help you to create a new subpanel under the Contacts module in Sugar using a custom link class and driven by SugarCRM 7's new SugarQuery API.

  1. Create a new link class

This should go into custom/modules/<YourModule>/YourNewLink.php and this class will act as the custom functionality that will build your link between the two records.

<?php

/**
 * Custom filtered link
 */
class YourNewLink extends Link2
{
    /**
     * DB
     *
     * @var DBManager
     */
    protected $db;

    public function __construct($linkName, $bean, $linkDef = false)
    {
        $this->focus = $bean;
        $this->name = $linkName;
        $this->db = DBManagerFactory::getInstance();
        if (empty($linkDef)) {
            $this->def = $bean->field_defs[$linkName];
        } else {
            $this->def = $linkDef;
        }
    }

    /**
     * Returns false if no relationship was found for this link
     *
     * @return bool
     */
    public function loadedSuccesfully()
    {
        // this link always loads successfully
        return true;
    }

    /**
     * @see Link2::getRelatedModuleName()
     */
    public function getRelatedModuleName()
    {
        return '<Your_Module>';
    }

    /**
     *
     * @see Link2::buildJoinSugarQuery()
     */
    public function buildJoinSugarQuery($sugar_query, $options = array())
    {
        $joinParams = array('joinType' => isset($options['joinType']) ? $options['joinType'] : 'INNER');
        $jta = 'active_other_invites';
        if (!empty($options['joinTableAlias'])) {
            $jta = $joinParams['alias'] = $options['joinTableAlias'];
        }

        $sugar_query->joinRaw($this->getCustomJoin($options), $joinParams);
        return $sugar_query->join[$jta];
    }

    /**
     * Builds main join subpanel
     * @param string $params
     * @return string JOIN clause
     */
    protected function getCustomJoin($params = array())
    {
        $bean_id = $this->db->quoted($this->focus->id);
        $sql = " INNER JOIN(";
        $sql .= "SELECT id FROM accounts WHERE id={$bean_id}"; // This is essentially a select statement that will return a set of ids that you can match with the existing sugar_query
        $sql .= ") accounts_result ON accounts_result.id = sugar_query_table.id";
        return $sql;
    }
}

The argument $sugar_query is a new SugarQuery object, the details of which are documented here. What you essentially need to do is extend this query with whatever join/filters you wish to add. This is done in the inner join I've specified.

Note: The inner join can get really complicated, so if you want a real working example, checkout modules/Emails/ArchivedEmailsLink.php and how the core sugar team use this. I can confirm however that this does work with custom joins.

Here is the getEmailsJoin to help you understand what you can actually produce via this custom join.

 /**
   * Builds main join for archived emails
   * @param string $params
   * @return string JOIN clause
   */
  protected function getEmailsJoin($params = array())
  {
      $bean_id = $this->db->quoted($this->focus->id);
      if (!empty($params['join_table_alias'])) {
          $table_name = $params['join_table_alias'];
      } else {
          $table_name = 'emails';
      }

      return "INNER JOIN (\n".
              // directly assigned emails
          "select eb.email_id, 'direct' source FROM emails_beans eb where eb.bean_module = '{$this->focus->module_dir}'
              AND eb.bean_id = $bean_id AND eb.deleted=0\n" .
" UNION ".
      // Related by directly by email
          "select DISTINCT eear.email_id, 'relate' source  from emails_email_addr_rel eear INNER JOIN email_addr_bean_rel eabr
          ON eabr.bean_id = $bean_id AND eabr.bean_module = '{$this->focus->module_dir}' AND
          eabr.email_address_id = eear.email_address_id and eabr.deleted=0 where eear.deleted=0\n" .
           ") email_ids ON $table_name.id=email_ids.email_id ";
  }
  1. Add a new vardef entry for the link field.

For this example, I'm going to create the custom link on the contacts module. So this code goes in custom/Extension/modules/Contacts/Ext/Vardefs/your_field_name.php

<?php
$dictionary["Contact"]["fields"]["your_field_name"] = array(
    'name' => 'active_other_invites',
    'type' => 'link',
    'link_file' => 'custom/modules/<YourModule>/YourNewLink.php',
    'link_class' => 'YourNewLink',
    'source' => 'non-db',
    'vname' => 'LBL_NEW_LINK',
    'module' => '<YourModule>',
    'link_type' => 'many',
    'relationship' => '',
);
  1. Add the new link as a subpanel

This goes under custom/Extension/modules/Contacts/Ext/clients/base/layouts/subpanels/your_subpanel_name.php

<?php
$viewdefs['Contacts']['base']['layout']['subpanels']['components'][] = array (
  'layout' => 'subpanel',
  'label' => 'LBL_NEW_LINK',
  'context' =>
  array (
    'link' => 'your_field_name',
  ),
);
  1. Add the label

Under

custom/Extension/modules/Contacts/Ext/Language/en_us.new_link.php

<?php
$mod_strings['LBL_ACTIVE_OTHER_INVITES'] = 'Your New Link';
  1. Quick Repair and Rebuild

That should hopefully get you started. Keep an eye on the sugarlogs while you're debugging your queries. I also found using xdebug and SugarQueries compileSql function invaluable in figuring out what I needed to do to get a working INNER JOIN statement.

I've found this to be a surprisingly powerful solution, it means that if you need to show information related to a module that might be a few joins away, this allows you to create the links manually without having to create pointless related fields in-between the two.

Upvotes: 0

Hachim IDRISSI
Hachim IDRISSI

Reputation: 217

I finaly find a solution :

Adding this few lines to "modules/AOS_Contracts/metadata/subpaneldefs.php" :

'securitygroups' => array(
        'top_buttons' => array(array('widget_class' => 'SubPanelTopSelectButton', 'popup_module' => 'SecurityGroups', 'mode' => 'MultiSelect'),),
        'order' => 900,
        'sort_by' => 'name',
        'sort_order' => 'asc',
        'module' => 'SecurityGroups',
        'refresh_page' => 1,
        'subpanel_name' => 'default',
        'get_subpanel_data' => 'SecurityGroups',
        'add_subpanel_data' => 'securitygroup_id',
        'title_key' => 'LBL_SECURITYGROUPS_SUBPANEL_TITLE',
    ),
  • QRR
  • Verifying permissions.

Upvotes: 3

Related Questions