Vtiger duplicates prevention. Change condition from AND to OR

Vtiger duplicates prevention. Change condition from AND to OR

Vtiger 7.3 has one great feature - checking records for duplicates before saving or changing. It works as follows - you go to the module settings (field management), in it you will have access to the "Duplicate Management" or Duplicate Prevention tab. When you go to this tab, you can specify the fields that you will check before saving.

Vtiger 7.3 has one great feature - checking records for duplicates before saving or changing. It works as follows - you go to the module settings (field management), in it you will have access to the "Duplicate Management" or Duplicate Prevention tab. When you go to this tab, you can specify the fields that you will check before saving.

On the screenshot in our example, we check new contacts for duplicates in two fields - Organization name and phone number. And the system works as follows - as soon as we try to create a new contact with the same organization and phone number, the system will not allow us to do this. Those. in this case, the AND condition works. The contact must be with the same organization AND phone number.

But what if we want to use the OR condition? Those. we want, for example, to check contacts for uniqueness by email or phone number. In other words, we want to achieve this behavior when the system checks for a match email, then the phone number, and if something of them is found, the system prohibits saving the record.

Fortunately, this is very easy to do. To do this, go to the file:

modules / Vtiger / handlers / CheckDuplicateHandler.php

We find a line around 165 (your number may be different), which looks like this:

$ conditionsSql = implode ("AND", $ conditions);

We delete it, insert the following text instead:

$ conditionsSql = implode ("OR", $ conditions);

Those, we changed only one word in it, and replaced AND with OR.

We save the file and now we can search for duplicates by OR condition.