Announcement

Collapse
No announcement yet.

Checking for Duplicate records

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

  • Checking for Duplicate records

    Hi,

    When we enter that record twice for entity type "Comany" and "Person", the system checks and alert a warning that the record is duplicate (see screencap1 attached). This does not happen with any other entity types. How can i enable the duplicate check for such entities?

    I know this may have been resolved before i am unable to locate it because of the search phrase. Assistance is most appreciated.
    Attached Files

  • #2
    Hi,
    please check this thread https://forum.espocrm.com/forum/gene...icate-checking.

    Comment


    • #3
      Hi Maximus ,

      Honestly, i am not a fully familiar with various aspects of the codes in Espocrm but I went through the forum link. There was so much variations but none address my problem. The entity we defined is a custom entity of the type "base". I used one of the examples but it gave me error 500 when i tested. This is what i did:

      The original code in custom/espo/services/Billrecord.php:


      Code:
      <?php
      
      namespace Espo\Custom\Services;
      
      class Billrecord extends \Espo\Core\Templates\Services\BasePlus
      {
      }
      Change to :

      Code:
      <?php
      namespace Espo\Custom\Services;
      
      use \Espo\ORM\Entity as Entity;
      
      class Lead extends \Espo\Modules\Crm\Services\Lead
      {
      protected function getDuplicateWhereClause(Entity $entity, $data)
      {
      return array(
      'AND' => array(
      array(
      'name' => $entity->get('name'),
      ),
      )
      );
      }
      }
      Last edited by murugappan; 07-24-2020, 08:02 AM.

      Comment


      • espcrm
        espcrm commented
        Editing a comment
        You can do it murugappan! I made a post in last thread but haven't gotten any confirmation so I left it in the dust corner. Hopefully your success can help out.

    • #4
      In the file /custom/Espo/Custom/Services/Billrecord.php you need to have this code:
      PHP Code:
      <?php

      namespace Espo\Custom\Services;

      use \
      Espo\ORM\Entity;

      class 
      Billrecord extends \Espo\Core\Templates\Services\BasePlus
      {
          protected function 
      getDuplicateWhereClause(Entity $entity$data)
          {
              if (!
      $entity->get('name')) {
                  return 
      false;
              }
              return [
                  
      'name' => $entity->get('name')
              ];
          }
      }

      Comment


      • #5
        Hi Maximus ,

        The code you posted worked for 1 field(?). So i modified the code to include another field. The following is the code but it didnt work. Gives me "bad server response" error:

        Code:
        <?php
        
        namespace Espo\Custom\Services;
        
        use \Espo\ORM\Entity;
        
        class Billrecord extends \Espo\Core\Templates\Services\BasePlus
        {
        protected function getDuplicateWhereClause(Entity $entity, $data)
        {
        if (!$entity->get('name') && (!$entity->get('claimnumber')) {
        return false;
        }
        return [
        'name' => $entity->get('name'),
        'claimnumber' => $entity->get('claimnumber'),
        
        ];
        }
        }
        2. I could not understand the symbols. The 'name' symbol is that the db name or entity name?

        Appreciate your help
        Last edited by murugappan; 07-24-2020, 03:09 PM.

        Comment


        • #6
          Hi murugappan
          I could not understand the symbols. The 'name' symbol is that the db name or entity name?
          My understanding is that 'name' refers to the field 'name' of the Billrecord record, so the filter is saying:

          "For an entity to be considered a duplicate, the value of the field 'name' of an existing record is equal to the value of the new entity's 'name' attribute"

          In your filter it would add the condition that the value of the exiting record's 'claimnumber' field be equal to the value of the 'claimnumber' attribute in the new entity.

          I suggest that you check the back end log (data/logs/) to see what kind of error is being triggered (Error 500 is just a generic flag) and an indication of what function in what script and line number is throwing the error to be able to further investigate.

          Comment


          • murugappan
            murugappan commented
            Editing a comment
            Hi, the code that i submitted, is that correct way to check for using 2 fields to check for duplicate?

          • telecastg
            telecastg commented
            Editing a comment
            I think that you have to remove the last "comma" in the return array like this:

            return [
            'name' => $entity->get('name'),
            'claimnumber' => $entity->get('claimnumber')
            ];

            Otherwise the "comma" after "('claimnumber')" indicates that array has a "third" element which is NULL and that is probably throwing off Espo, but if this doesn't help, check the back-end log to learn more about the error.

            If you are not familiar with PHP troubleshooting you can check this post https://forum.espocrm.com/forum/deve...gging-php-code
        Working...
        X