Duplicate checking fields - V8.0

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • Ashif Malayil
    replied
    Originally posted by rabii
    But if you want to force the user to not create the entity when a duplicate is found, you need to add the code mentioned by Yuri above

    PHP Code:
    if (recordService\skipDuplicateCheck()) {
    recordService\throwForbidden("No duplicate check bypass allowed.");
    }
    ​ 
    Meaning when system find a duplicate if the user clicks on create they will get the error (No duplicate bypass allowed) and this will stop them from creating duplicated record.
    There is one issue, User 1 has created 1 Lead after that that User 2 also created same Lead, in this time it's not showing any duplicate alert or the access denied error of the formula we added. It's straightly getting created. I think this because of the ACL of users. I need to restrict this. How can i resolve this?​
    Last edited by Ashif Malayil; 06-13-2024, 07:52 AM.

    Leave a comment:


  • Davidjuan
    replied

    It sounds like you've set up the duplicate check fields, but you’re still able to create duplicate entries. Here are a few steps you can follow to ensure the duplicate check works correctly:

    1. Verify Duplicate Check Configuration:
    - Make sure the fields you've selected for duplicate checking are correctly configured.
    - Ensure the duplicate check feature is enabled in the settings.

    2. Set the Name Field as Unique:
    - Since you're using the default name field as a serial number, it should be unique. You might need to enforce this at the database level to prevent duplicates.

    3. Backend Configuration:
    - Check if there's a unique constraint on the `name` field in your database schema. If not, you may need to add it.
    - For example, in SQL, you can set a unique constraint like this:
    ```sql
    ALTER TABLE your_table_name
    ADD CONSTRAINT unique_name UNIQUE (name);
    ```

    4. Custom Validation:
    - Implement custom validation logic in your application to check for duplicates before saving new entries. This can be done in the backend code where entries are processed.

    5. Clear Cache and Restart:
    - Sometimes, changes require a cache clear or a restart of your application for them to take effect.

    If you’ve already done the above and the issue persists, please provide more details about your setup or any error messages you might be seeing. This will help in diagnosing the problem more precisely.

    I hope this helps! Let me know if you need further assistance.​

    Leave a comment:


  • PrototypeX
    replied
    This formula

    if (recordService\skipDuplicateCheck()) {
    recordService\throwForbidden("No duplicate check bypass allowed.");
    }​


    works as intended if f you are creating manually but if you are converting a lead to account and is already there its seams to me that is ignoring it.
    Any suggestions?
    Thank you​

    Leave a comment:


  • shalmaxb
    replied
    I think I found the reason, why it is not working on create record. The duplicate check depends on the common field "vernissage", means, that the record is checked against that field, which is present in existing exhibition items, but not in a not yet saved item, as it will be fetched through the relationship only on saving. That means, that the duplicate check for a related field cannot work, as the value isn`t present yet.

    I added now for that entity an API before save script:

    Code:
    if (!recordService\skipDuplicateCheck() || entity\isAttributeChanged('ausstellungsnummer')) {
    $id = record\findOne('WerkeAusstellungen', 'vernissage', 'desc', 'ausstellungsnummer=', ausstellungsnummer);
    
    if ($id) {
    recordService\throwDuplicateConflict($id);
    }
    }


    and now it works (though I do not really understand yet, how that works).

    To explain, what this script does:

    For a new record it looks for the current exhibition/vernissage ordered by the most recent vernissage date (because that is an exhibition in preparation and so the numbering may be changed until opening). If the number is present already, it throws the duplicate warning.

    If an existing record gets inserted a new number for some reason, the duplicate check will be against the already existing numbers and if present already throws the duplicate warning as well.
    Last edited by shalmaxb; 10-23-2023, 06:26 PM.

    Leave a comment:


  • shalmaxb
    commented on 's reply
    No API before formula script. The duplicate check takes place in the (linked) entity only and itself, I check the conditions in this one entity.

  • rabii
    commented on 's reply
    if it works on update it must work on create by default. can you check if you have a API before formula script that triggers the message.

  • shalmaxb
    commented on 's reply
    this check works as desired on update. That means, when I change a number in the list to a number already existing, it throws the warning and displays the existing work with that number. Would it not work on recordNew?

  • rabii
    commented on 's reply
    i am not sure that duplicate check would work here, because you are trying to check duplicate based on linked entities. you might consider another solution as the duplicate check will not work i guess.

  • shalmaxb
    replied
    The exhibition items are in a from exhibition separated entity linked by relationship. So I have the items for all exhibitions in the entity WerkeAusstellungen. There might be items 1 to 10 for exhibition X and 1 to 15 for exhibition Y and so on.
    So I do not need to check, if in exhibtion X there is already a number, which I need for exhibition Y, I only have to check in exhibition items Y.
    The duplicate check has to happen in the linked entity with all items, limited to the items, that belong to one certain exhibition.

    I know it is not easy to understand, nor to explain.....
    But in fact it is quite simple.

    Click image for larger version

Name:	wvz_exhibition_item_numbering.jpg
Views:	312
Size:	49.5 KB
ID:	98934

    Leave a comment:


  • rabii
    replied
    what do you mean ? i am honestly confused when you said you don't care if the number exist in another exhibition ? so what is the point f using duplicate check on the number then. if i understand this is to do only with the exhibition entity and has nothing to do with the items.

    The number should be unique for an unique exhibition, but the number could appear in another exhibition again of course.

    Leave a comment:


  • shalmaxb
    replied
    I need a condition, that checks a duplicate number in the given exhibition. The number should be unique for an unique exhibition, but the number could appear in another exhibition again of course.

    In other words, the duplicate check should only happen for the current exhibition, where I number the existing and new items (artwork) exhibited in that one exhibition. I don`t care if a number is already existing in another exhibition.
    Last edited by shalmaxb; 10-23-2023, 10:28 AM.

    Leave a comment:


  • rabii
    replied
    It seems that it is not working because you have an AND operator there, which means that both conditions should happen to apply the duplicate check (ausstellungsnummer && vernissage) meaning that there should an existing record that has same value provided for both fields. Not sure if this is what you mean because it is confusing that you have an OR condition on your if statement but you apply an AND expression on the result. when creating a new record do you need the new exhibition to have a unique (ausstellungsnummer) AND a unique (vernissage) ?

    Leave a comment:


  • shalmaxb
    replied
    I got my custom duplicate check working, but only on update of the respective field. On new record it does not work.

    Here is my code:

    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 WerkeAusstellungen implements WhereBuilder
    {
    public function build(Entity $entity): ?WhereItem
    {
    $orBuilder = OrGroup::createBuilder();
    
    $toCheck = false;
    
    if ($entity->get('ausstellungsnummer') || $entity->get('vernissage')) {
    $orBuilder->add(
    Cond::and(
    Cond::equal(
    Cond::column('ausstellungsnummer'),
    $entity->get('ausstellungsnummer')
    ),
    Cond::equal(
    Cond::column('vernissage'),
    $entity->get('vernissage')
    )
    )
    );
    
    $toCheck = true;
    }
    
    return $orBuilder->build();
    }
    }


    The entity (and class) is WerkeAusstellungen, what means ArtworkExhibition. Every exhibition has a number of artworks, which are sequencial numbered from 1 to n. This way it is for every exhibiton.
    In the exhibition I want to duplicate check the already manual entered numbers (varchar field), so that every number in one exhibition can appear only once
    In the code "ausstellungsnummer" is that number, "vernissage" is a date field for the opening of the exhibition, which gives the condition, that the numer is for one certain exhibition.
    When I try to update a number in a given list with an already existing number, it throws the warning for duplicate, displaying the other record with that number. Hence, it works as it should.

    Though, when I create a new record it does not have any effect and so it is possible to enter an already existing number again.

    Where and how will I have to declare a function to work for new records as well?

    Leave a comment:


  • rabii
    commented on 's reply
    the new function is a plus for a non technical users. they can just choose the fields and the crm will map them in an Or statement. However the system allows you to always create your own custom checker as it won't be possible to cover all use cases with the introduced function. If you face any issues we are here to help mate

  • shalmaxb
    replied
    thanks rabii, I see (the linked discussion sheds more light on this function). Unfortunately the built in function is a bit limited in the fields, that can be used and creating more complex conditions (at least for me).
    I will see, if I can build in the needed functionality into my custom duplicate checkers.

    Leave a comment:

Working...