Hi, I was able to present the information duplication message, but even so the system is letting you save the "Save" button, is it possible to completely block the recording of the new duplicate record?
Announcement
Collapse
No announcement yet.
Completely lock duplicate recording
Collapse
X
-
Hello
if you don't need upgrade save way of customization, modify 'setup' method client/src/views/modals/duplicate.js and leave empty array in button list
if you want to do it right, you need to override showDuplicate (client/src/views/record/detail.js) method in custom record view of you entity and and use own duplicate view (https://github.com/espocrm/documenta...ustom-views.md)
- Likes 1
-
Hello Tanya, thank you!
I want to leave enabled the update, I even managed to block duplication in the update, but for a new record the system warns that there is duplicity but still lets record this duplicate data, that's what I want to block.
After I changed this setting ($ checkForDuplicatesInUpdate = true), I was able to block duplicity only in the update, but in a new registry not yet. (Espocrm / application / Espo / Services / Record.php)
You can help me and pass the path and the command or parameter that I change in the system to block a new duplicate die.1 Photo
Comment
-
Hello, Please see below to remove save button for Espo 7+
Scenario:
For this example, assume we have some Entity called MyTestEntity.
We do not want to duplicate records of this Entity if 'name' attribute already exists in db table my_test_entity (created by Espo).
Step 1: Create DuplicateWhereBuilder
custom/Espo/Custom/Classes/DuplicateWhereBuilders/MyTestEntity.php
PHP 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 MyTestEntity implements WhereBuilder
{
/**
* @inheritDoc
*/
public function build(Entity $entity): ?WhereItem
{
$orBuilder = OrGroup::createBuilder();
$toCheck = false;
if ($entity->get('name')) {
$orBuilder->add(
Cond::equal(
Cond::column('name'),
$entity->get('name')
),
);
$toCheck = true;
}
if (!$toCheck) {
return null;
}
return $orBuilder->build();
}
}
Step 2: Create custom duplicate modal view and override setup function to only include Cancel Button
client/custom/src/views/modals/duplicate-no-save-btn.js
Code:define('custom:views/modals/duplicate-no-save-btn', 'views/modals/duplicate', function (Dep) { //console.log('custom:views/modals/duplicate-no-save-btn.js'); return Dep.extend({ setup: function () { this.buttonList = [ { name: 'cancel', label: 'Cancel' } ]; this.scope = this.options.scope; this.duplicates = this.options.duplicates; } }); });
Step 3: Create custom record/detail and record/edit views for MyTestEntity. Override errorHandlerDuplicate function to use custom modal duplicate view above
client/custom/src/views/my-test-entity/record/detail-no-save-btn-on-duplicate.js
Code:define('custom:views/my-test-entity/record/detail-no-save-btn-on-duplicate', 'views/record/detail', function (Dep) { //console.log('custom:views/my-test-entity/record/detail-no-save-btn-on-duplicate.js'); return Dep.extend({ errorHandlerDuplicate: function (duplicates) { this.notify(false); this.createView('duplicate', 'custom:views/modals/duplicate-no-save-btn', { scope: this.entityType, duplicates: duplicates, model: this.model, }, (view) => { view.render(); }); }, }); });
Code:define('custom:views/my-test-entity/record/detail-small-no-save-btn-on-duplicate', 'views/record/detail-small', function (Dep) { //console.log('custom:views/my-test-entity/record/detail-small-no-save-btn-on-duplicate.js'); return Dep.extend({ errorHandlerDuplicate: function (duplicates) { this.notify(false); this.createView('duplicate', 'custom:views/modals/duplicate-no-save-btn', { scope: this.entityType, duplicates: duplicates, model: this.model, }, (view) => { view.render(); }); }, }); });
client/custom/src/views/my-test-entity/record/edit-no-save-btn-on-duplicate.js
Code:define('custom:views/my-test-entity/record/edit-no-save-btn-on-duplicate', 'views/record/edit', function (Dep) { //console.log('custom:views/my-test-entity/record/edit-no-save-btn-on-duplicate.js'); return Dep.extend({ errorHandlerDuplicate: function (duplicates) { this.notify(false); this.createView('duplicate', 'custom:views/modals/duplicate-no-save-btn', { scope: this.entityType, duplicates: duplicates, model: this.model, }, (view) => { view.render(); }); }, }); });
Code:define('custom:views/my-test-entity/record/edit-small-no-save-btn-on-duplicate', 'views/record/edit-small', function (Dep) { //console.log('custom:views/my-test-entity/record/edit-small-no-save-btn-on-duplicate.js'); return Dep.extend({ errorHandlerDuplicate: function (duplicates) { this.notify(false); this.createView('duplicate', 'custom:views/modals/duplicate-no-save-btn', { scope: this.entityType, duplicates: duplicates, model: this.model, }, (view) => { view.render(); }); }, }); });
Step 4: Edit/Create clientDefs/MyTestEntity.json to tell EspoCRM to use our new detail and edit view files
custom/Espo/Custom/Resources/metadata/clientDefs/MyTestEntity.json
Code:{ "recordViews":{ "detail":"custom:views/my-test-entity/record/detail-no-save-btn-on-duplicate", "detailSmall":"custom:views/my-test-entity/record/detail-small-no-save-btn-on-duplicate", "edit":"custom:views/my-test-entity/record/edit-no-save-btn-on-duplicate", "editSmall":"custom:views/my-test-entity/record/edit-small-no-save-btn-on-duplicate" }, "controller": "controllers/record", ... }
Step 5: Edit/Create recordDefs/MyTestEntity.json to tell EspoCRM to use our duplicateWhereBuilder
custom/Espo/Custom/Resources/metadata/recordDefs/MyTestEntity.json
Code:{ "duplicateWhereBuilderClassName": "Espo\\Custom\\Classes\\DuplicateWhereBuilders\\MyTestEntity", "updateDuplicateCheck": true, ... }
Caution:
While this seems to also work in inlineEdit mode, I notice that after canceling the custom duplicate modal dialog in inlineEdit mode, the inline edit field retains the edited value even after canceling the inline-edit. If you refresh the page the old value comes back. I'm not sure how to fix that issue, but the duplicated record is not created in inlineEdit mode either with this approach. It just takes an extra step to refresh. Screenshots below. Last edited by czcpf; 11-22-2022, 09:58 PM. Reason: Edited to include editSmall and detailSmall for cases where entity is being created/edited from related entity
Comment
-
Originally posted by czcpf View PostHello, Please see below to remove save button for Espo 7+
Scenario:
For this example, assume we have some Entity called MyTestEntity.
We do not want to duplicate records of this Entity if 'name' attribute already exists in db table my_test_entity (created by Espo).
Step 1: Create DuplicateWhereBuilder
custom/Espo/Custom/Classes/DuplicateWhereBuilders/MyTestEntity.php
PHP 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 MyTestEntity implements WhereBuilder
{
/**
* @inheritDoc
*/
public function build(Entity $entity): ?WhereItem
{
$orBuilder = OrGroup::createBuilder();
$toCheck = false;
if ($entity->get('name')) {
$orBuilder->add(
Cond::equal(
Cond::column('name'),
$entity->get('name')
),
);
$toCheck = true;
}
if (!$toCheck) {
return null;
}
return $orBuilder->build();
}
}
Step 2: Create custom duplicate modal view and override setup function to only include Cancel Button
client/custom/src/views/modals/duplicate-no-save-btn.js
Code:define('custom:views/modals/duplicate-no-save-btn', 'views/modals/duplicate', function (Dep) { //console.log('custom:views/modals/duplicate-no-save-btn.js'); return Dep.extend({ setup: function () { this.buttonList = [ { name: 'cancel', label: 'Cancel' } ]; this.scope = this.options.scope; this.duplicates = this.options.duplicates; } }); });
Step 3: Create custom record/detail and record/edit views for MyTestEntity. Override errorHandlerDuplicate function to use custom modal duplicate view above
client/custom/src/views/my-test-entity/record/detail-no-save-btn-on-duplicate.js
Code:define('custom:views/my-test-entity/record/detail-no-save-btn-on-duplicate', 'views/record/detail', function (Dep) { //console.log('custom:views/my-test-entity/record/detail-no-save-btn-on-duplicate.js'); return Dep.extend({ errorHandlerDuplicate: function (duplicates) { this.notify(false); this.createView('duplicate', 'custom:views/modals/duplicate-no-save-btn', { scope: this.entityType, duplicates: duplicates, model: this.model, }, (view) => { view.render(); }); }, }); });
Code:define('custom:views/my-test-entity/record/detail-small-no-save-btn-on-duplicate', 'views/record/detail-small', function (Dep) { //console.log('custom:views/my-test-entity/record/detail-small-no-save-btn-on-duplicate.js'); return Dep.extend({ errorHandlerDuplicate: function (duplicates) { this.notify(false); this.createView('duplicate', 'custom:views/modals/duplicate-no-save-btn', { scope: this.entityType, duplicates: duplicates, model: this.model, }, (view) => { view.render(); }); }, }); });
client/custom/src/views/my-test-entity/record/edit-no-save-btn-on-duplicate.js
Code:define('custom:views/my-test-entity/record/edit-no-save-btn-on-duplicate', 'views/record/edit', function (Dep) { //console.log('custom:views/my-test-entity/record/edit-no-save-btn-on-duplicate.js'); return Dep.extend({ errorHandlerDuplicate: function (duplicates) { this.notify(false); this.createView('duplicate', 'custom:views/modals/duplicate-no-save-btn', { scope: this.entityType, duplicates: duplicates, model: this.model, }, (view) => { view.render(); }); }, }); });
Code:define('custom:views/my-test-entity/record/edit-small-no-save-btn-on-duplicate', 'views/record/edit-small', function (Dep) { //console.log('custom:views/my-test-entity/record/edit-small-no-save-btn-on-duplicate.js'); return Dep.extend({ errorHandlerDuplicate: function (duplicates) { this.notify(false); this.createView('duplicate', 'custom:views/modals/duplicate-no-save-btn', { scope: this.entityType, duplicates: duplicates, model: this.model, }, (view) => { view.render(); }); }, }); });
Step 4: Edit/Create clientDefs/MyTestEntity.json to tell EspoCRM to use our new detail and edit view files
custom/Espo/Custom/Resources/metadata/clientDefs/MyTestEntity.json
Code:{ "recordViews":{ "detail":"custom:views/my-test-entity/record/detail-no-save-btn-on-duplicate", "detailSmall":"custom:views/my-test-entity/record/detail-small-no-save-btn-on-duplicate", "edit":"custom:views/my-test-entity/record/edit-no-save-btn-on-duplicate", "editSmall":"custom:views/my-test-entity/record/edit-small-no-save-btn-on-duplicate" }, "controller": "controllers/record", ... }
Step 5: Edit/Create recordDefs/MyTestEntity.json to tell EspoCRM to use our duplicateWhereBuilder
custom/Espo/Custom/Resources/metadata/recordDefs/MyTestEntity.json
Code:{ "duplicateWhereBuilderClassName": "Espo\\Custom\\Classes\\DuplicateWhereBuilders\\MyTestEntity", "updateDuplicateCheck": true, ... }
Caution:
While this seems to also work in inlineEdit mode, I notice that after canceling the custom duplicate modal dialog in inlineEdit mode, the inline edit field retains the edited value even after canceling the inline-edit. If you refresh the page the old value comes back. I'm not sure how to fix that issue, but the duplicated record is not created in inlineEdit mode either with this approach. It just takes an extra step to refresh. Screenshots below.
Comment
Comment