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

Fullscreen
1
2
3
4
5
$dictionary['RTPOL_OLP']['fields']['contacts_rtpol_olp_1contacts_ida']['filter_definition'] = [
[
'account_id' => '#accounts_rtpol_olp_1accounts_ida'
]
];
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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

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

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    $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,
    );
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    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'
    ),
    ),
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    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

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    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'
    ),
    ),
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     

    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.

  • Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <?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',
    ),
    ),
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Here you go.

  • I am not sure why you referenced that link. My relationships are working fine, just none of my filters work. I have created three separate filters, 2 based on relationships and one just based on a field that might or might not be empty. None of those filters work at all.

  • Do you have "links" in both side of the relationship?

    I think the problem is the value that you use on the filter relate. 

    Fullscreen
    1
    2
    3
    'filter_relate' => array(
    'accounts_rtpol_olp_1accounts_ida' => 'account_id'
    ),
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    In my code "'intermediary_account_id'" is a link created on the custom module side.

    I suggested that post because for me it was fundamental to understand and create the links on both side of the modules.

    Fullscreen
    1
    2
    3
    'filter_relate' => array(
    'intermediary_account_id' => 'account_id'
    ),
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Ok now the filter is popping up but the dynamic field is blank. I had to create a calculated field that is supposed to populated with the account_id.

  • Ok that Filter is working. Thank you. I had to create a calculated field with related($accounts_rtpol_olp_1,"id") as a formula.

1 2