Announcement

Collapse
No announcement yet.

Duplicate Check don`t get it to work

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

  • Duplicate Check don`t get it to work

    Hi,
    I need a duplicate check for a custom entity. I read all posts about this subject, worked through the docs, but whatever I try, I always get error 500, nothing in the log-file.

    I have a custom entity (BasePlus), where I want to duplicate check the "name" field. The name of the entity is "Werke"

    Here is the code I tried (following the docs):

    Code:
    <?php
    
    namespace Espo\Custom\Classes\DuplicateWhereBuilders;
    
    use Espo\Core\Duplicate\WhereBuilder;
    
    use Espo\ORM\Query\Part\Condition as Cond;
    use Espo\ORM\Query\Part\WhereItem;
    use Espo\ORM\Query\Part\Where\OrGroup;
    use Espo\ORM\Entity;
    
    class Werke implements WhereBuilder
    {
    protected function getDuplicateWhereClause(Entity $entity, $data)
    {
    if (!$entity->get('name')) {
    return false;
    }
    return [
    'name' => $entity->get('name')
    ];
    }
    }
    Help is appreciated, thank you.​

  • #2
    Did you read this post? It was for v6, I'm not sure if it still working though. I haven't use Properties in a while so I haven't test.

    Hi Can someone let me know how the duplicate check works on Espocrm? Also when i try to import a csv and even the duplicate check is enabled, it imports all the records although some phone numbers and email addresses are in the crm. The duplicate check doesnt seem to be working properly. also how to i add a phone number for

    Comment


    • #3
      Check the webserver error log to see the error.

      Your class does not follow what is in documentation. https://docs.espocrm.com/development/duplicate-check/

      Your class does not implement interface that it declares to implement. It does not have 'build' method. It does not return a proper type. I recommend using IDE.

      Comment


      • item
        item commented
        Editing a comment
        this post must be a post-it..
        i begin to understand many. Thank you Yuri

    • #4
      Originally posted by espcrm View Post
      Did you read this post? It was for v6, I'm not sure if it still working though. I haven't use Properties in a while so I haven't test.

      https://forum.espocrm.com/forum/gene...8211#post68211
      I read all threads about duplicate-check, but they have all different code and I did not find the reason for e.g. when to code extend and when to implement. In the documentation, which I followed, there is:

      Code:
      class Werke implements WhereBuilder
      In one of the other threads this line writes:

      Code:
      class RealEstateProperty extends \Espo\Modules\RealEstate\Services\RealEstateProperty
      Maybe this is ridiculos for a programmer, which I am not. But for me I do not see any logic, that would lead me to the right solution.

      yuri, in the documentation the class is so:

      Code:
      {
      "duplicateWhereBuilderClassName": "Espo\\Custom\\Classes\\DuplicateWhereBuilders\\Lead"
      }
      I put it so (my entitie`s name is Werke:

      Code:
      {
      "duplicateWhereBuilderClassName": "Espo\\Custom\\Classes\\DuplicateWhereBuilders\\Werke"
      }
      Then I modified the php code only by adding my entity and taking away the and/or condition. I cannot see, where there would be something missing, I followed, what I see in the documentation.

      What I want is to have the "name" field of my custom entity Werke duplicate checked.
      I admit that it might not work, because my skills are not sufficient. My hope was to be able to learn that by documentation and examples, what not did happen.

      Comment


      • #5
        You mixed the old method that is deprecated with the new method. Just follow what is in documentation and ignore what is on the forum that was posted more than 2 years ago. If there's something in the documentation that contradicts something on the forum, ignore the forum. Even new posts may suggest old deprecated methods.

        Comment


        • #6
          Try re-utilizing the checker class for Company entities. It checks the name and email addresses.

          Code:
          {
              "duplicateWhereBuilderClassName": "Espo\\Classes\\DuplicateWhereBuilders\\Company"
          }​
          Defining classes with custom logic requires some programming knowledge level.

          Comment


          • #7
            Checking only name (not tested):

            Code:
            <?php
            namespace Espo\Custom\Classes\DuplicateWhereBuilders;
            
            use Espo\Core\Duplicate\WhereBuilder;
            
            use Espo\ORM\Query\Part\Condition as Cond;
            use Espo\ORM\Query\Part\WhereItem;
            use Espo\ORM\Entity;
            
            class YourEntity implements WhereBuilder
            {
                public function build(Entity $entity): ?WhereItem
                {
                    if ($entity->get('name')) {
                        return Cond::equal(
                            Cond::column('name'),
                            $entity->get('name')
                        );
                    }
            
                    return null;
                }
            }
            Last edited by yuri; 03-21-2023, 04:40 PM.

            Comment


            • #8
              yuri, thank you very much, I appreciate your efforts. But unfortunately this code throws an error:

              [2023-03-21 15:46:48] ERROR: Slim Application Error Type: ParseError Code: 0 Message: syntax error, unexpected token &quot;}&quot; File: /var/www/vhosts/xxxxxxxxxx/custom/Espo/Custom/Classes/DuplicateWhereBuilders/Werke.php Line: 19 Trace: #0

              When I put the code in a php code checker, the same error in line 19 curly bracket appears. Line 19 is before "return null;"

              Comment


              • #9
                It's because the forum added extra characters. You need to remove them.

                Comment


                • yuri
                  yuri commented
                  Editing a comment
                  I managed to remove them in the post above. Try to copy again.

              • #10
                yuri, yes now it works. I will keep in mind not to copy from the browser. Thank you very much, your great help is appreciated!

                Comment


                • esforim
                  esforim commented
                  Editing a comment
                  Do you know how we can extend it?

                  It say here in docs:

                  // Here you can add more conditions.

              • #11
                Lucky I put a disclaimer it for v6

                I guess I will give this a try to update considering what is being said above. Hope it easier to do now and I can adopt to new method.

                Here is my code if anyone want to use it:
                Last edited by esforim; 03-22-2023, 07:02 AM.

                Comment


                • esforim
                  esforim commented
                  Editing a comment
                  This is cool: "Duplicate check is performed upon record creation. Optionally, it can be enabled for record update."

              • #12
                EDIT EDIT: IGNORE EVERYTHING! I figure it out, I didn't see this other 'code' I need to change. This is what happen when you don't code. All seem to be working now! (I think). Just need to try enable on "Upon Update" somewhere now.

                Code:
                class Lead implements WhereBuilder​
                Reposted here: https://forum.espocrm.com/forum/gene...9795#post89795
                Last edited by esforim; 03-22-2023, 07:10 AM.

                Comment


                • shalmaxb
                  shalmaxb commented
                  Editing a comment
                  your filename is RealEstateProperty.php, the from my understanding the class name is RealEstateProperty.
                  Don´t take this for granted, because, what I (or better: Yuri) solved yesterday, I never would have been able to achieve by myself. Still trying to understand the whole thing.

                  And you did read about the copy from forum/browser can insert hidden characters, which make the code invalid.

                  It has to be DuplicateWhereBuilder, no slash
                  Last edited by shalmaxb; 03-22-2023, 07:03 AM.

                • esforim
                  esforim commented
                  Editing a comment
                  shalmaxb I figure it out, and edit the first post. I might move all this in Learning and not cog up your thread... I try find delete button.

                  I use the copy/paste button from the documents, which by right should be no issue and can confirm. Just need to edit 1 more code which all working all!
                  Last edited by esforim; 03-22-2023, 07:11 AM.

              • #13
                I guess the next question is, how we can modified this part so it show additional information.

                For example I just create a duplicate check for a custom entity call Asset. In this asset I assign a code to each Asset and will be checking duplicated against that.

                In this photo I add a "Car" and I think this is quite universal but all car got a "Plate Number", which I use as the MainCode.

                I create the code here if anyone want to borrow it, it essential just using Yuri code above with a slight change...

                Anyway here is the issue: Be good if we can display additional data as it only showing "Name" at the moment.

                Click image for larger version

Name:	image.png
Views:	236
Size:	11.8 KB
ID:	89797

                Comment


                • #14
                  For the duplicatecheck on update here how I did it:

                  Click image for larger version  Name:	image.png Views:	0 Size:	11.5 KB ID:	89799

                  Here is my code online which I hopefully slowly add in my duplicate check that can use feel free to use:

                  Last edited by esforim; 03-22-2023, 07:34 AM. Reason: it is correct. that how you do it!

                  Comment

                  Working...
                  X