SugarClub will be undergoing scheduled maintenance and will be inaccessible beginning on Friday, 10 April 2026 (15:00 UTC | 11am EDT | 1am AEST on 11 April).
This maintenance period will end on 
Monday, 13 April 2026 (12:00 UTC | 8am EDT | 10pm AEST). 

sugarcrm filter on relative field

How can i add  filter on related field  .  like I have user type related field on which I have want to show only user related user with some role  . how is this possible  ?

i tried through this 

https://sugarclub.sugarcrm.com/dev-club/f/questions-answers/1209/how-to-add-an-initial-filter-to-studio-created-relate-field-drawers

bt not working 

Parents
  • You can extend the vardef file to add a "filter_definition". For example, in the field custom/Extension/modules/<module>/Ext/Vardefs/sugarfield_<field_name>.php, you can add something like:


    $dictionary
    ['<module>']['fields']['<field_name>']['filter_definition'] = [
    [
    'aclroles.name' => '<role_name>'
    ]
    ];

    Then do a quick repair and rebuild - and by default, it will auto-filter based on the definition above - but this doesn't enforce the filter, users are free to remove the filter and set any record they want, but the default search will filter by the role you specify.

Reply
  • You can extend the vardef file to add a "filter_definition". For example, in the field custom/Extension/modules/<module>/Ext/Vardefs/sugarfield_<field_name>.php, you can add something like:


    $dictionary
    ['<module>']['fields']['<field_name>']['filter_definition'] = [
    [
    'aclroles.name' => '<role_name>'
    ]
    ];

    Then do a quick repair and rebuild - and by default, it will auto-filter based on the definition above - but this doesn't enforce the filter, users are free to remove the filter and set any record they want, but the default search will filter by the role you specify.

Children
  • Hey Neeranja P, 

    Could this also work for restricting contacts for accounts in related modules?

    Overview:

    When an Account is selected and the user goes to choose the Contact, I want to restrict the Contacts available to only those on the Account....but the the detail here is that account is a dynamic values (not like the '<role name'>)..

    Link to  Simirar case

    Example: ( Getting only the contacts of the account selected <TestAccount>)

    I've tried like you mention above but  im not sure what to consider as my <module>(cases or account) and sugarfield (in custom/Extension/modules/<module>/Ext/Vardefs/sugarfield_<field_name>.php)...is not throwing any errors nor the queries expected.

     

  • Well, I guess you can do an onlyread field, as same as you do with the relationship of the role field you can do with readonly.
    If I am sure you must do 

    $dictionary['<module>']['fields']['<field_name>']['filter_definition']['readonly'] = true;

    And that converts the field in a simply label, not editable by the user.