How to check for duplicate record using workflow

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • murugappan
    Active Community Member
    • Aug 2017
    • 467

    How to check for duplicate record using workflow

    Hi,

    We installed this following code under custom folder to check for duplicate record:


    HTML 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')
            ];
        }
    }
    
    ​
    This code works when we create the entity record online but does not seem to work when the record is created using Workflow. This is the workflow definition (the entity name field = Bill/Cover No. field in Workflow. Appreciate any help, please.


    Click image for larger version

Name:	Screenshot_1.png
Views:	458
Size:	37.1 KB
ID:	83810

  • yuri
    Member
    • Mar 2014
    • 8444

    #2
    There's no functionality to call the duplication checking logic neither from a workflow action nor from a formula-script.

    As a workaround you can use a formula-script condition (in your workflow) that checks whether a record with the same name exists. https://docs.espocrm.com/administrat.../#recordexists
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • murugappan
      Active Community Member
      • Aug 2017
      • 467

      #3
      Hi yuri thank you for the update and help. I have a problem with the suggestion. This is what i am trying to achieve:

      HTML Code:
      ifThen(record\exists('Billrecord', 'name=', billNumber),
      alert('Duplicate Record'));​
      That is, if the record exists, i do not want to create the record as shown in my earlier initial post # 1 above. Also need to notify the user of the error. Please advise. Tq.

      Comment

      • yuri
        Member
        • Mar 2014
        • 8444

        #4
        Unfortunately, there's no ability to invoke any UI modal from the formula (or workflow).
        If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

        Comment

        • murugappan
          Active Community Member
          • Aug 2017
          • 467

          #5
          Hi yuri , its ok. I adopted your suggestion on using the "record/exists" formula. What i did was to provide a new status "Duplicate #" in the related record that was created. Advised the users on the workaround and got thumbs up for implementation. Hopeful of seeing pop alert functionality at some point in time. Thank you so much for the help.

          Comment

          Working...