Duplicate Checking On Save in Sugar (Part 1)

By Adam Chodoff • January 25th, 2016
Audiences: Developers

One thing that comes up often when configuring a new Sugar instance is the question of duplicate checking on saving a record. Now, while many aspects of the user experience are detailed and configurable via Studio at this point, the logic of matching potential duplicates on save remains a bit hidden.

Given that there doesn’t seem to be much in the way of documentation on the default behavior, we figured we’d put together a post detailing the default logic for some common modules in Sugar. In a follow-up post, we’ll describe how to go in and change these filters to suit your needs.

Note: this is distinct from the logic used when importing records via the import feature.

Accounts

To find out what logic Sugar is using by default, we need to head to the vardefs file for each module. Let’s open up the vardefs file for accounts, under modules/Accounts/vardefs.php. There is an array entitled ‘duplicate_check’, which then has an entry for ‘FilterDuplicateCheck’. Under that entry we get the following code for the ‘filter_template’ array:

This details the logic which will be built into a filter later on in execution. So therefore we have:

Account X is a duplicate of new account Y if:

X → name equals Y → name
OR
X → duns_num equals Y → duns_num
OR
(

X → name starts with Y → name
AND
(

X → billing_address_city starts with Y → billing_address_city
OR
X → shipping_address_city starts with Y → shipping_address_city

 )

)

We won’t show the PHP for the following modules—just the pseudocode version for easier reference. You can always take a look at the vardefs file for the module you’re interested in to see how these are constructed.

Cases

Case X is a duplicate of new case Y if:

X → name starts with Y → name
AND
X → status is NOT ‘Closed’
AND
X → account_id equals Y → account_id

 

Contacts

Contact X is a duplicate of new contact Y if:

X → first_name starts with Y → first_name
AND
X → last_name starts with Y → last_name
AND
X → account_id equals Y → account_id
AND
X → dnb_principal_id equals Y → dnb_principal_id

Leads

Lead X is a duplicate of new lead Y if:

(

X → status is NOT ‘Converted’
OR
X → status is NULL

)

AND

(

(

X → account_name starts with Y → account_name
AND
X → first_name starts with Y → first_name
AND
X → last_name starts with Y → last_name
AND
X → dnb_principal_id equals Y → dnb_principal_id

)
OR
X → phone_work equals Y → phone_work

)

Opportunities

Opportunity X is a duplicate of new opportunity Y if:

X → name starts with Y → name
X → sales_stage is NOT ‘Closed Lost’
X → sales_stage is NOT ‘Closed Won’
X → account_id equals Y → account_id

Targets

Target X is a duplicate of new target Y if:

(

X → account_name starts with Y → account_name
AND
X → first_name starts with Y → first_name
AND
X → last_name starts with Y → last_name
AND
X → dnb_principal_id equals Y → dnb_principal_id

)

OR
X → phone_work equals Y → phone_work

 

Look out for another post where we will detail how to make changes to these formulas!

More From This Author
Adam Chodoff
Application Specialist at UpCurve Cloud