Friday, June 20, 2014

Custom/Conditional Duplicate Detection on Account

Hi All,
It’s been a while for me sharing some good stuffs of CRM through my blog so now here I am. J
Recently in my organization we received a very good request from users where they needed a Duplicate Detection on Accounts and we thought that it’s a very simple task for us since now CRM 2013 Service Pack 1 have brought back our old and very desirable OOB duplicate detection screen which we are used to see in previous CRM versions. However in our requirement gathering meeting with users we came across a special request from them which said that they need conditional Duplicate Detection on Accounts which means that only certain type of accounts should be detected for duplication whereas other type should be allowed to be duplicated.
While doing some research over the feasibility of this we came across this blog by Andrii (Thanks Andrii!) which pointed us to go back and check out CRM 2013 SDK. In SDK there was already a custom solution provided by Microsoft for implementing the Duplicate Detection functionality (Details can be found in the link above) which we can use it easily and modify it to embed the conditions on which our users want Duplicate Detection to be fired. It was a happy day that we found this ready-made solution provided by Microsoft but happiness was short lived when we read through the “Read Me” file provided which said that the provided solution was only for Contacts and Lead entity. So we had to build the solution for Accounts entity using the files provided for Contacts and Lead.
Solution
Here you can download the source code which is built for implementing the same SDK solution but for “Accounts” entity. The download is a zip of all the web resources (No CRM Solution) which you will need to implement the functionality.
I have made some below changes which was not part of the original solution:
  • Added “Account Number” column in Duplicate Detection Pop-up screen. For that below files were modified.
    • ShowDuplicateAccounts.html (HTML file)
    • ShowDuplicateAccounts.js (JS file)
  • Added logic in “SDK.DuplicateDetection.js” file to open the record from Duplicate Detection screen in a new Pop-up window instead of it getting opened in the same window. The changes done were:
    • Added a new method “OpenNewWindow” which will be called whenever user clicks on any record to get it open in a new Pop-up or window.
  • (Optional - Not included in the code) If you have same type of requirement of conditional Duplicate Detection then you can add your checking condition in the beginning of “onSave” method of “ShowDuplicateAccounts.js” file (Step 3 Below).

Implementation steps are already available in the link provided above as well as in SDK in “ReadMe.doc” on path “SDK2013\SampleCode\JS\DuplicateDetection”. However I will still reiterate the same here for easy reference.
Implementation Steps
  1. Import all the web resources provided in the download with the same “Name” as shown in below screenshot however your prefix may differ (here it is “new_”).
    • The reason for the “Name” to be specific is that those same paths are referred in other files.
  1. Open Account entity form and add “SDK.DuplicateDetection.js” JS web resource library.
  2. Add event handler for “OnSave” event referencing the above library calling the function named “SDK.Sample.DuplicateDetection.onSave”
  3. Check “Pass execution context as first parameter” checkbox.
  4. Add below parameters in other parameters textbox. (Make sure you change the prefix below if different)
false, "account",  "accountid",  ["name", "accountnumber", "emailaddress1"],
"new_/duplicateDetection/ShowDuplicateAccounts.html",
"dialogHeight: 250px; dialogWidth: 600px; resizable: yes; status: no;"



Result: OnSave event of Account having a potential duplicate record.

Hope you find this post helpful. Feel free to post your valuable comments or suggestions. 

Thank You !!! J

No comments:

Post a Comment