Initial Filter on a subpanel "Link an Existing"

Has anyone been able to add an initial filter on a subpanel? In Opportunities I want to limit the Contacts a user sees to only those linked to the selected Account. I already have the filter built and tested, just need to add it to a subpanel.

  • You need to add the attributes relationship_file and relationship_class into target relationship and the define the relationship class accordingly, so you will be able to override the method 'buildSugarQueryRoleWhere' accordingly:

    New attributes in the relationship

    Fullscreen
    1
    2
    $dictionary["Account"]["relationships"]["account_cases"]["relationship_file"] = "custom/data/Relationships/CustomOne2MBeanRelationship.php";
    $dictionary["Account"]["relationships"]["account_cases"]["relationship_class"] = "CustomOne2MBeanRelationship";
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Changes in the relationship class, from the core relationship UserBasedRelationship

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    protected function buildSugarQueryRoleWhere($sugar_query, $table = "", $ignore_role_filter = false)
    {
    $sugar_query = parent::buildSugarQueryRoleWhere($sugar_query, $table, $ignore_role_filter);
    $sugar_query->join[$table]->on()->equals($table.'.'.$this->userField,$GLOBALS['current_user']->id);
    return $sugar_query;
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • I am sorry but I am not sure how your answer solves the problem of applying a dynamic filter to a subpanel. The relationship in question is a OOTB Many:Many relationship between Opportunites and Contacts.

  • Ok thanks to Ross and engineers at Faye, I have confirmed how to do this. Applying a custom filter when opening a drawer. - Dev Answers & Best Practices - DevClub - SugarClub (sugarcrm.com) explains it and give samples to help.