Filter Pop-up based on relationship

Anyone able to get this working? I tried what suggested in sugarcrm filter on relative field - Dev Answers & Best Practices - DevClub - SugarClub so far not working. Here is the code I am adding to custom/Extension/modules/RTPOL_OLP/Ext/Vardefs/sugarfield_contacts_rtpol_olp_1contacts_ida.php

$dictionary['RTPOL_OLP']['fields']['contacts_rtpol_olp_1contacts_ida']['filter_definition'] = [
  [
    'account_id' => '#accounts_rtpol_olp_1accounts_ida'
  ]
];

I am trying to filter Contacts based on Account, but getting this working will lead to other filters.

Parents
  • You have to create a filter in Contacts module in custom/Extension/modules/Contacts/Ext/clients/base/filters/basic

    $viewdefs['Contacts']['base']['filter']['basic']['filters'][] = array(
        'id' => 'filterContactsByAccountId',
        'name' => 'LBL_FILTER_CONTACTS_BY_ACCOUNT_ID',
        'filter_definition' => array(       
            array(
                'account_id' => ''
            )
        ),
        'editable' => true,
        'is_template' => true,
    );

    And then in record.php of module RTPOL_OLP in the field Contact you call the initial filter:

    array (
        'name' => 'intermediary_contact_name',
        'label' => 'LBL_INTERMEDIARY_CONTACT_NAME',
    	  //the name of the filter template
    	'initial_filter' => 'filterContactsByAccountId',
    
    	//the display label for users
    	'initial_filter_label' => 'LBL_FILTER_CONTACTS_BY_ACCOUNT_ID',
    
    	//the dynamic filters to pass to the templates filter definition
    	//please note the index of the array will be for the field the data is being pulled from
    	'filter_relate' => array(
    		'intermediary_account_id' => 'account_id'
    	),
      ),

    I got this from a previous post but I didn't kept the link....

    I hope this help....

  • I tried but this is not working. I created the filter exact as you have shown, then added the reference in the record.php like so

     array (
                    'name' => 'contacts_rtpol_olp_1_name',
                    'label' => 'LBL_CONTACTS_RTPOL_OLP_1_NAME_FIELD_TITLE',
                    //the name of the filter template
                    'initial_filter' => 'filterContactsByAccountId',
    
                    //the display label for users
                    'initial_filter_label' => 'LBL_FILTER_CONTACTS_BY_ACCOUNT_ID',
    
                    //the dynamic filters to pass to the templates filter definition
                    //please note the index of the array will be for the field the data is being pulled from
                    'filter_relate' => array(
                      'accounts_rtpol_olp_1accounts_ida' => 'account_id'
                    ),
                  ),
     

    I must still be missing something.

    Also, here is the link you are looking for Sugar Developer Guide 13.1 - Sugar Support (sugarcrm.com).

  • Show the code of the relation between module  RTPOL_OLP and the module Accounts.

  • <?php
    // created: 2023-09-12 08:21:18
    $dictionary["accounts_rtpol_olp_1"] = array (
      'true_relationship_type' => 'one-to-many',
      'from_studio' => true,
      'relationships' => 
      array (
        'accounts_rtpol_olp_1' => 
        array (
          'lhs_module' => 'Accounts',
          'lhs_table' => 'accounts',
          'lhs_key' => 'id',
          'rhs_module' => 'RTPOL_OLP',
          'rhs_table' => 'rtpol_olp',
          'rhs_key' => 'id',
          'relationship_type' => 'many-to-many',
          'join_table' => 'accounts_rtpol_olp_1_c',
          'join_key_lhs' => 'accounts_rtpol_olp_1accounts_ida',
          'join_key_rhs' => 'accounts_rtpol_olp_1rtpol_olp_idb',
        ),
      ),
      'table' => 'accounts_rtpol_olp_1_c',
      'fields' => 
      array (
        'id' => 
        array (
          'name' => 'id',
          'type' => 'id',
        ),
        'date_modified' => 
        array (
          'name' => 'date_modified',
          'type' => 'datetime',
        ),
        'deleted' => 
        array (
          'name' => 'deleted',
          'type' => 'bool',
          'default' => 0,
        ),
        'accounts_rtpol_olp_1accounts_ida' => 
        array (
          'name' => 'accounts_rtpol_olp_1accounts_ida',
          'type' => 'id',
        ),
        'accounts_rtpol_olp_1rtpol_olp_idb' => 
        array (
          'name' => 'accounts_rtpol_olp_1rtpol_olp_idb',
          'type' => 'id',
        ),
      ),
      'indices' => 
      array (
        0 => 
        array (
          'name' => 'idx_accounts_rtpol_olp_1_pk',
          'type' => 'primary',
          'fields' => 
          array (
            0 => 'id',
          ),
        ),
        1 => 
        array (
          'name' => 'idx_accounts_rtpol_olp_1_ida1_deleted',
          'type' => 'index',
          'fields' => 
          array (
            0 => 'accounts_rtpol_olp_1accounts_ida',
            1 => 'deleted',
          ),
        ),
        2 => 
        array (
          'name' => 'idx_accounts_rtpol_olp_1_idb2_deleted',
          'type' => 'index',
          'fields' => 
          array (
            0 => 'accounts_rtpol_olp_1rtpol_olp_idb',
            1 => 'deleted',
          ),
        ),
        3 => 
        array (
          'name' => 'accounts_rtpol_olp_1_alt',
          'type' => 'alternate_key',
          'fields' => 
          array (
            0 => 'accounts_rtpol_olp_1rtpol_olp_idb',
          ),
        ),
      ),
    );
    

    Here you go.

Reply
  • <?php
    // created: 2023-09-12 08:21:18
    $dictionary["accounts_rtpol_olp_1"] = array (
      'true_relationship_type' => 'one-to-many',
      'from_studio' => true,
      'relationships' => 
      array (
        'accounts_rtpol_olp_1' => 
        array (
          'lhs_module' => 'Accounts',
          'lhs_table' => 'accounts',
          'lhs_key' => 'id',
          'rhs_module' => 'RTPOL_OLP',
          'rhs_table' => 'rtpol_olp',
          'rhs_key' => 'id',
          'relationship_type' => 'many-to-many',
          'join_table' => 'accounts_rtpol_olp_1_c',
          'join_key_lhs' => 'accounts_rtpol_olp_1accounts_ida',
          'join_key_rhs' => 'accounts_rtpol_olp_1rtpol_olp_idb',
        ),
      ),
      'table' => 'accounts_rtpol_olp_1_c',
      'fields' => 
      array (
        'id' => 
        array (
          'name' => 'id',
          'type' => 'id',
        ),
        'date_modified' => 
        array (
          'name' => 'date_modified',
          'type' => 'datetime',
        ),
        'deleted' => 
        array (
          'name' => 'deleted',
          'type' => 'bool',
          'default' => 0,
        ),
        'accounts_rtpol_olp_1accounts_ida' => 
        array (
          'name' => 'accounts_rtpol_olp_1accounts_ida',
          'type' => 'id',
        ),
        'accounts_rtpol_olp_1rtpol_olp_idb' => 
        array (
          'name' => 'accounts_rtpol_olp_1rtpol_olp_idb',
          'type' => 'id',
        ),
      ),
      'indices' => 
      array (
        0 => 
        array (
          'name' => 'idx_accounts_rtpol_olp_1_pk',
          'type' => 'primary',
          'fields' => 
          array (
            0 => 'id',
          ),
        ),
        1 => 
        array (
          'name' => 'idx_accounts_rtpol_olp_1_ida1_deleted',
          'type' => 'index',
          'fields' => 
          array (
            0 => 'accounts_rtpol_olp_1accounts_ida',
            1 => 'deleted',
          ),
        ),
        2 => 
        array (
          'name' => 'idx_accounts_rtpol_olp_1_idb2_deleted',
          'type' => 'index',
          'fields' => 
          array (
            0 => 'accounts_rtpol_olp_1rtpol_olp_idb',
            1 => 'deleted',
          ),
        ),
        3 => 
        array (
          'name' => 'accounts_rtpol_olp_1_alt',
          'type' => 'alternate_key',
          'fields' => 
          array (
            0 => 'accounts_rtpol_olp_1rtpol_olp_idb',
          ),
        ),
      ),
    );
    

    Here you go.

Children