Duplicate checking fields - V8.0

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • rabii
    commented on 's reply
    AFAK you should be able to keep your custom duplicatecheck class as it is and should work even with latest version v8 and above, i am using a custom duplicate check for few entities in different projects and it works fine. here is a discussion with yuri about it https://github.com/espocrm/espocrm/i...ent-1628924603

  • shalmaxb
    replied
    Hi, until now I used a custom duplicate check, which would be obsolete with the new function. With the above script it works.

    Will I have to delete the scripts I used before version 8?

    And is it possible to have a duplicate check depending on two fields at once?

    I have an entity, where I organize exhibitions. Every exhibition has items, which are numbered from 1 to n. So one exhibition may have item 1 to 10, the other one 1 to 15. As it is checked now, I get a duplicate warning, when I place the number 1 in a new exhibition, when there is already a number 1 in a former exhibition.
    So it would be necessary to have something like: If in exhibition X there is a number 1, it cannot have another number 1 (duplicate check warning). If in exhibition X there is a number 1, it may have a number 1 in exhibition Y (no duplicate check warning).
    Last edited by shalmaxb; 10-22-2023, 02:22 PM.

    Leave a comment:


  • wdbruwer
    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.
    Thanks, I will keep that on record, for now we happy with the pop up showing the duplicate. If I notice users ignoring that I will implement.

    Leave a comment:


  • rabii
    replied
    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.

    Leave a comment:


  • wdbruwer
    replied
    Originally posted by rabii
    you are welcome Make sure to change Account with your entity. if you face any issues let me know
    Worked perfectly, changed entity & works for 2 fields that I need to keep unique. I get the pop up warning for duplicate & shows the duplicate.

    Leave a comment:


  • yuri
    replied
    To forbid bypass duplicate checking, one can use

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

    Leave a comment:


  • yuri
    replied
    This should work w/o the script. The same logic.

    Leave a comment:


  • rabii
    replied
    you are welcome Make sure to change Account with your entity. if you face any issues let me know

    Leave a comment:


  • wdbruwer
    replied
    Originally posted by rabii
    you will a code like this, add it to your entity administration > Entity Manager > Your Entity > Formula > API Before Save Script and use the code below

    PHP Code:
    if (!recordService\skipDuplicateCheck()) {
    $id record\findOne('Account'nullnull'name='name);

    if (
    $id) {
    recordService\throwDuplicateConflict($id);
    }
    }
    ​ 
    You are a star, thank you so much.

    Leave a comment:


  • rabii
    replied
    you will a code like this, add it to your entity administration > Entity Manager > Your Entity > Formula > API Before Save Script and use the code below

    PHP Code:
    if (!recordService\skipDuplicateCheck()) {
        
    $id record\findOne('Account'nullnull'name='name);

        if (
    $id) {
            
    recordService\throwDuplicateConflict($id);
        }
    }
    ​ 

    Leave a comment:


  • wdbruwer
    replied
    Originally posted by espcrm
    It will only do a Duplicate Check, it won't prevent from creating duplicate. You can use Before Save Formula to deny all duplicate creation
    Understood thanks, sadly that is outside my scope of understanding in the world of code & Scripting, So I'm going to ask the most annoying question, how do I do that?

    Leave a comment:


  • esforim
    replied
    It will only do a Duplicate Check, it won't prevent from creating duplicate. You can use Before Save Formula to deny all duplicate creation

    Leave a comment:


  • wdbruwer
    started a topic Duplicate checking fields - V8.0

    Duplicate checking fields - V8.0

    I have upgraded to V8.0.0.0 today as I saw the duplicate check is now available. I have selected the fields that should be checked for duplicate, however I seem to be still missing something as I can stil create duplicate entries.

    To give a background, I am using the default name field as my serial number field, as such this needs to be a unique field and can't be duplicate.

    Is there something I need to change in the backend to prevent users from being able to update/create duplicate entries?
Working...