How to Use Dashlet Filters with Custom Fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Carolus
    Junior Member
    • May 2025
    • 4

    #1

    How to Use Dashlet Filters with Custom Fields

    I’m looking for a way to expand the "Primary Filter" options in EspoCRM for the Contact entity.

    Current Setup:
    • Custom Field:
      • Name: Privatcontact
      • Type: Checklist (with "Yes option)
    • Primary Filter Limitations:
      Currently, I only see two default options:
      • All
      • Portal Users
    Goal:
    I want to create a dashlet on the homepage that displays only contacts marked as "Privatcontact = Yes".

    Questions:
    1. Is there a way to add custom filters (like Privatcontact = Yes) to the primary filter dropdown?
    2. If not, what’s the best workaround to achieve this (e.g., via Advanced Pack, workflows, or a custom view)
    I’d appreciate any guidance or steps to resolve this.
  • item
    Active Community Member
    • Mar 2017
    • 1567

    #2
    Hi,
    i know, we can do filter with Advanced Pack but forget.

    via code :




    custom/Espo/Custom/Classes/Select/Account/PrimaryFilters/Actual.php
    PHP Code:
    
    namespace Espo\Custom\Classes\Select\Account\PrimaryFilters;
    
    use Espo\Core\Select\Primary\Filter;
    use Espo\ORM\Query\SelectBuilder;
    
    class Actual implements Filter
    {
        public function __construct()
        {}
    
        public function apply(SelectBuilder $queryBuilder): void
        {
            $queryBuilder->where([
                'status' => ['New', 'Active'],
            ]);
        }
    } 
    
    custom/Espo/Custom/Resources/metadata/selectDefs/Account.json

    PHP Code:
    
    {
        "primaryFilterClassNameMap": {
            "Actual": "Espo\\Custom\\Classes\\Select\\Account\\PrimaryFilters\\Actual"
        }
    } 
    
    custom/Espo/Custom/Resources/metadata/clientDefs/Account.json

    PHP Code:
    {
        "filterList": [
            {
                "name": "Actual",
                "style": "warning"
            }
        ]
    }
    clearCache, rebuild

    I hope, i have not forget other needed code..
    Last edited by item; 05-05-2025, 12:44 PM.
    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

    Comment

    • Carolus
      Junior Member
      • May 2025
      • 4

      #3
      Thanks for your responce.
      I cant find this stucture on the hosting
      until the map /custom/Espo/Custom is there, in this map I see only map Controllers and Resources.
      I don't have Advanced Packed, thats possible the reason thats the structure is different.

      If there is an another solution I appreciate that.

      Comment


      • item
        item commented
        Editing a comment
        Hi,
        create the directory.. follow the path as my sample, change Account to Contact .. and the filter 'status' => ['New', 'Active'], to yours privatcontact => 'Yes' something so. see UpperCase LowerCase too
    • Carolus
      Junior Member
      • May 2025
      • 4

      #4
      Hi,

      I made the changes, now i see the message:

      ' kan dit verzoek momenteel niet verwerken.

      HTTP ERROR 500
      '

      Comment


      • item
        item commented
        Editing a comment
        this is the result of a bad json file.
        You need to check if each file is json correct, if you have make copy-past from forum, he add somes extra bad characters.
    • Carolus
      Junior Member
      • May 2025
      • 4

      #5
      I understand, and PHP is ok when I copy ?

      Comment

      Working...