Announcement

Collapse
No announcement yet.

Duplicate checking

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

  • Duplicate checking

    I am new to espocrm, I would like to know if espocrm has duplicate checking function for email or phone for existing contact/lead/account database or when adding new/edit contact/lead/account?
    Many thanks,
    Khai

  • #2
    Hi

    It can be done very easily.

    Change this file:
    application/Espo/Modules/Crm/Services/Contact.php

    PHP Code:
    <?php
    /************************************************************************
     * This file is part of EspoCRM.
     *
     * EspoCRM - Open Source CRM application.
     * Copyright (C) 2014  Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
     * Website: http://www.espocrm.com
     *
     * EspoCRM is free software: you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation, either version 3 of the License, or
     * (at your option) any later version.
     *
     * EspoCRM is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with EspoCRM. If not, see http://www.gnu.org/licenses/.
     ************************************************************************/ 

    namespace Espo\Modules\Crm\Services;

    use 
    \Espo\ORM\Entity;

    class 
    Contact extends \Espo\Services\Record
    {
        protected function 
    getDuplicateWhereClause(Entity $entity)
        {
            return array(
                
    'OR' => array(
                    array(
                        
    'firstName' => $entity->get('firstName'),
                        
    'lastName' => $entity->get('lastName'),
                    ),
                    array(
                        
    'emailAddress' => $entity->get('emailAddress'),
                    ),
                ),
            );
        }
    }

    Comment


    • khai@outlook.com
      khai@outlook.com commented
      Editing a comment
      Hi Yuri,

      That was really cool. all works fine.

      I am working on the LDAP authentication, but it keeps saying server authentication failure and not allow to me load application

      Thank you for you kindly help and great CRM application.
      Khai

  • #3
    yuri it works while creating the new contact but not while editing the contact. What to do for the phone number?

    Comment


    • #4
      EspoCRM – Open Source CRM Application. Contribute to espocrm/espocrm development by creating an account on GitHub.


      Set protected $checkForDuplicatesInUpdate = true; in your Service class.

      Comment


      • #5
        How can I define table uniqueness. Like do not allow create leads for records having same name and (phone or email).

        My use case is:

        on same name and email: update lead
        on same name and phone: update lead
        on same name but different phone and email: create lead

        So, i want uniqueness to be set in database level.

        unique (name, emailAddress),
        unique (name, phoneNumber)
        Last edited by theBuzzyCoder; 02-26-2018, 08:51 AM.

        Comment


        • #6
          Is this a content of custom/Espo/Custom/Services/Lead.php ?

          Comment


          • #7
            Hi tanya ,

            Yes. It is the contents of custom/Espo/Custom/Services/Lead.php


            PHP Code:
            <?php
            namespace Espo\Modules\Crm\Services;

            use 
            \Espo\ORM\Entity as Entity;

            class 
            Lead extends \Espo\Services\Record
            {
                protected function 
            getDuplicateWhereClause(Entity $entity$data)
                {
                    return array(
                        
            'OR' => array(
                            array(
                                
            'firstName' => $entity->get('firstName'),
                                
            'lastName' => $entity->get('lastName'),
                            ),
                            array(
                                
            'emailAddress' => $entity->get('emailAddress'),
                            ),
                        ),
                    );
                }
            }
            ?>

            Comment


            • #8
              Aha, you've changed the class name, but not the namespace Espo\Custom\Services;
              And if you don't want to lose existing lead functionality, your class has to extend Espo\Modules\Crm\Services\Lead

              Comment


              • #9
                Hi tanya ,

                Thanks. That helped. Also, how can I put condition like

                check duplicate using: name && (email || phone)

                Comment


                • #10
                  This worked for me
                  PHP 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(
                                      
                  'firstName' => $entity->get('firstName'),
                                      
                  'lastName' => $entity->get('lastName'),
                                  ),
                                  
                  'OR' => array(
                                      array(
                                          
                  'phoneNumber' => $entity->get('phoneNumber'),
                                      ),
                                      array(
                                          
                  'emailAddress' => $entity->get('emailAddress'),
                                      ),
                                  ),
                              )
                          );
                      }
                  }
                  ?>

                  Comment


                  • #11
                    This worked perfectly for me on Opportunity! Just leaving my mark here in case I need to come back to this post.
                    File: custom/Espo/Custom/Services/Opportunity.php
                    Last edited by khopper; 03-23-2018, 03:54 PM.

                    Comment


                    • #12
                      How can I Disable Duplicate checking for a specific custom Entity "MDB"?
                      I tried adding the following to the file \custom\Espo\Custom\Services\MDB.php and these errors start showing up in the logs.

                      Code:
                      {
                          protected function getDuplicateWhereClause(Entity $entity, $data)
                          {
                              return array(
                                  'AND' => array(
                                      array(
                                          'name' => $entity->get('name'),
                                      ),
                                      'OR' => array(
                                          array(
                                              'btn' => $entity->get('btn'),
                                          ),
                                      ),
                                  )
                              );
                          }
                      }

                      [2019-05-02 18:34:10] Espo.WARNING: E_WARNING: Declaration of Espo\Custom\Services\MDB::getDuplicateWhereClause( Espo\Custom\Services\Entity $entity, $data) should be compatible with Espo\Core\Templates\Services\Company::getDuplicate WhereClause(Espo\ORM\Entity $entity, $data) {"code":2,"message":"Declaration of Espo\\Custom\\Services\\MDB::getDuplicateWhereClau se(Espo\\Custom\\Services\\Entity $entity, $data) should be compatible with Espo\\Core\\Templates\\Services\\Company::getDupli cateWhereClause(Espo\\ORM\\Entity $entity, $data)","file":"/var/www/espocrm/custom/Espo/Custom/Services/MDB.php","line":5,"context":{"file":"/var/www/espocrm/custom/Espo/Custom/Services/MDB.php"}} []
                      Last edited by khopper; 05-02-2019, 06:42 PM.

                      Comment


                      • #13
                        Resolved, I had to adjust php file since custom entity is type "company" in directory: application\Espo\Core\Templates\Services\Company.p hp

                        From:
                        Code:
                        {
                            protected function getDuplicateWhereClause(Entity $entity, $data)
                            {
                                return array(
                                    'name' => $entity->get('name')
                                );
                            }
                        }
                        To:
                        Code:
                        {
                            protected function getDuplicateWhereClause(Entity $entity, $data)
                            {
                                return array(
                                    'AND' => array(
                                        array(
                                            'name' => $entity->get('name'),
                                        ),
                                        'OR' => array(
                                            array(
                                                'btn' => $entity->get('btn'),
                                            ),
                                        ),
                                    )
                                );
                            }
                        }
                        Last edited by khopper; 05-02-2019, 08:32 PM.

                        Comment


                        • #14
                          this method in my case does not work, if you have working code, please post it here

                          Comment


                          • Exsto
                            Exsto commented
                            Editing a comment
                            what do you want to get exactly?

                        • #15
                          if possible Lead.php file

                          Comment

                          Working...
                          X