Announcement

Collapse
No announcement yet.

Custom filters within dashlet

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom filters within dashlet

    I would like to be able to use custom made filters on the dashboard for the Record List dashlet.

    According to this Github thread such a feature via the UI isn't planned and you need to code it: https://github.com/espocrm/espocrm/issues/484

    The instructions on how to do so appear incomplete as far as I can tell. This page gives the most useful information: https://devcrm.it/custom-filters

    This was helpful for making filters for Text strings. But not very useful for dates. Specifically I would like something like what is discussed here: https://forum.espocrm.com/forum/gene...7287#post47287

    But the instructions look incomplete. Exactly what file do you put this code into?

    Code:
    "defaultFilterData": {
               "advanced": {
                    "closeDate": {
                            "type": "lastXDays",
                            "number": 45,
                            "value": 45
                     }
                }
         }

    I have this in custom/Espo/Custom/Resources/metadata/clientDefs/Opportunity.json for example. It doesn't do anything.

    Only the instructions at devcrm.it work. But again, this is not helpful for dates. It's also not a 1 to 1 match with the user made filters (which I would like).

    Any help would be appreciated.

  • #2
    Assuming you are using ESPO 7.0 or above.

    To create a custom dashlet you will be having a dashlet_name.json under custom/Espo/Custom/Resources/metadata/dashlets right, so you will have to add a field in the options->defaults->searchData. Here you'll need to create an entry something like "closedDate" or whatever.

    Example code:
    Code:
    "searchData": {
        "primary": "closedDate"
    }
    Then you will need to create a selector class under /custom/Espo/Custom/Classes/Select/<EntityName>/PrimaryFilters with the file ClosedDate.php and class name as ClosedDate.

    This file will have your custom filter code in the apply function:
    Code:
    public function apply(SelectBuilder $queryBuilder): void
    {
      $date = new DateTime();
      $dateString = $date->format('Y-m-d');
      $queryBuilder->where([
        'closeDate' => $dateString
      ]);
    }
    This class then needs to be referenced under custom/Espo/Custom/Resources/metadata/selectDefs/EntityName.json something like:
    Code:
    {
      "primaryFilterClassNameMap": {
        "closedDate": "Espo\\Custom\\Classes\\Select\\<EntityName>\\PrimaryFilters\\ClosedDate",
      }
    }

    Clear Cache and Rebuild.
    This should filter your custom dashlet.

    Note, the implementation in ESPO 6 is different.

    Hope this helps. Cheers!

    Comment


    • #3
      I've been trying to find a way to filter the standard 'My Activities' dashlet to only show overdue activities and have difficulty understanding your advice on creating a custom dashlet - particularly which files need to be created and where.

      I may be using a sledgehammer to crack a walnut and wondered if you had any advice on the best way to go about this?

      Comment


      • #4
        The instructions I found at https://devcrm.it/custom-filters were the most completed. I used that to create the filters.

        That made them available within the Dashboard feature of EspoCRM. Then simply deployed to teams.

        Comment


        • #5
          AgentT

          I tried to follow your instructions but I get error

          Error 500

          InjectableFactory: Class 'Espo\Custom\Classes\Select\Task\PrimaryFilters\Jo bTypeOther' does not exist.

          Can you please help on this matter. I checked each file name 4 time already.

          Thanks

          Comment

          Working...
          X