Donnerstag, 5. März 2009

Pimp your Duplicate Detection with Phonetic Matching (Soundex)

Ever wanted to get some more "fuzziness" in your detection rules? Then Soundex as a phonetic algorithm will be your friend. There are some caveats but for some applications it might be useful. The nice thing is, that it's super-easy to implement.

Let's consider two options (in your project you might want to go for a "best of both worlds" approach by using both):

Method1 Clientside: Generating the Soundex-Code at the onSave event
Pro: Quick and easy implementation
Con: Will not work on imports or Bulk Operations

Step by step:

1) add a custom field "new_soundex_lastname" to the desired entity (lead, account, contact or any custom entity)

2) add the field to the form

3) add this onSave event:
function soundex(str) {
// original from

var i, j, l, r, p = isNaN(p) ? 4 : p > 10 ? 10 : p < 4 ? 4 : p;
var m = {BFPV: 1, CGJKQSXZ: 2, DT: 3, L: 4, MN: 5, R: 6};
var r = (s = (str+'').toUpperCase().replace(/[^A-Z]/g, "").split("")).splice(0, 1);
var sl = 0;

= s.length;
for (i = -1, l = sl; ++i < l;) {
for (j in m) {
if (j.indexOf(s[i]) + 1 && r[r.length-1] != m[j] && r.push(m[j])) {

return r.length > p && (r.length = p), r.join("") + (new Array(p - r.length + 1)).join("0");


4) add a duplicate rule & publish

5) enjoy life without unneccessary duplicates ;-)

Method 2 Plugin: Firing at Pre-Create event
Pro: Works on Imports
Con: A bit more work

You can also create a plugin that generates the soundex-code, just use an example on how to do that.

7 Kommentare:

  1. Again a great blog post Mario Raunig! I really admire you!

    Keep up your fantastic work and keep on blogging! Your contribution to the MS CRM community is highly appreciated!

  2. ... besonders die abgebildeten duplikate sind wirklich unnötig. Schöner Seitenhieb. :-D

  3. You have really great taste on catch article titles, even when you are not interested in this topic you push to read it

  4. I am reading this article second time today, you have to be more careful with content leakers. If I will fount it again I will send you a link

  5. Wonderful post! Youve made some very astute observations and I am thankful for the the effort you have put into your writing. Its clear that you know what you are talking about. I am looking forward to reading more of your sites content.
    Dynamics crm training

  6. This does not apply to latest Dynamics CRM version. Please update!

  7. i have never thought it would be so easy to do. thank you for your explanatory introduction