Global Search Includes Completed Tasks

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robbyslaughter
    Junior Member
    • Dec 2017
    • 20

    #1

    Global Search Includes Completed Tasks

    I've searched through the forums and not found anyone else talking about this. If you search for a keyword that is in a Task, Global Search will return all tasks---even those that have been completed.

    Is this something that can be changed? I don't think so at present, but it would be a nice feature for a future version of EspoCRM.

    Of course one can search within the Tasks section itself and filter out tasks with Status = Completed, but it would be helpful to have this configurable for Global search,
  • item
    Active Community Member
    • Mar 2017
    • 1569

    #2
    Hi,

    In Admin/settings General tab, you ccan add Task entity in Global Search "Defines which record types are searchable with Global Search."
    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

    Comment

    • yuri
      EspoCRM product developer
      • Mar 2014
      • 9927

      #3
      Currently we don't have such an ability. It's often appropriate to show completed records as well. Having a global parameter to switch between modes might be not the best solution. The question is how to switch between modes without complicating the UI.

      Comment

      • robbyslaughter
        Junior Member
        • Dec 2017
        • 20

        #4
        Originally posted by yuri
        Currently we don't have such an ability. It's often appropriate to show completed records as well. Having a global parameter to switch between modes might be not the best solution. The question is how to switch between modes without complicating the UI.
        Something like this is what I would imagine:

        Click image for larger version

Name:	image.png
Views:	8
Size:	9.6 KB
ID:	125740

        The left hand side with the dropdown would work as it does for any list search---some predefined options.

        For the right hand side I think you'd need a two level menu, first to list the entities that were configured. Something like:

        Click image for larger version

Name:	image.png
Views:	8
Size:	47.9 KB
ID:	125741

        Comment

        • robbyslaughter
          Junior Member
          • Dec 2017
          • 20

          #5
          This worked for me.

          File: custom/Espo/Custom/Tools/GlobalSearch/Service.php


          HTML Code:
          // Added constant:
          private const EXCLUDE_COMPLETED = ['Task'];
          
          // In find(), added one line after deduplicate():
          $dedupedEntities = $this->deduplicate($rawResult->getCollection());
          + $filteredEntities = $this->filterOutCompleted($dedupedEntities);
          
          - $sliced = array_slice($dedupedEntities, $offset, $resolvedMaxSize + 1);
          + $sliced = array_slice($filteredEntities, $offset, $resolvedMaxSize + 1);
          
          // Added new private method:
          private function filterOutCompleted(array $entities): array
          {
              return array_values(array_filter($entities, function (Entity $entity): bool {
                  if (!in_array($entity->getEntityType(), self::EXCLUDE_COMPLETED, true)) {
                      return true;
                  }
                  return $entity->get('status') !== 'Completed';
              }));
          }
          How it works: EspoCRM's global search service already fetches the statusField for each returned entity (Task's is status). This override post-filters the results to drop any Task with status === 'Completed'. Add other entity types to EXCLUDE_COMPLETED to apply the same rule elsewhere.​

          Comment

          Working...