This article has been updated to ensure the variables that are passed can take into account a wider range of characters in passed names including umlauts, accents and cedillas.
Although this article describes a technique for adding dedupe behaviour to the Lead table it may be adapted for other entities.
The first thing I should point out is that CRM's dedupe behaviour is not really deduplication. It is rather a preentry search that helps avoid users entering duplicated records. The system has this built-in feature available for the Company and Person tables. It actually gets very sophisticated with the Company table once you start using the match rules and the company name clean up feature.
I have made this example as simple as possible.
Even though the lead table is designed to hold low quality 'suspect' data and early stage unqualified 'prospect' details a project's requirements sometimes mean that duplicate lead entries should be prevented.
I have modelled my new lead behaviour on the existing New Person and New Company screens. To create my version of the "New Lead" behaviour I built 2 ASP pages and wrote some code that I added to an existing screen's "custom content".
The first ASP page allows the user to enter initial search data (First Name and Last Name). The page can be called from the New system menu. I only used the person first name and last name, but hopefully you are be able to adapt this as you require. The page takes the entered data and passes it to the second page. This first page shows how you can build a page from scratch and control where the data is submitted.
The second page collects the passed data. It checks whether there is an existing lead for the submitted data. It you have added additional fields you will need to alter this code.
If there is no match the screen will redirect to the standard Lead entry screen but if there is a match then the results of the search are displayed. The user can then select the lead that is the best fit and carry on with their work or they can choose to ignore the potential duplication and click to create a new lead.
A last bit of code needs to be added to the leadpersonscreen. It picks up the initially submitted data and adds it to the fields on the new lead screen. It has been written so that it does not break the existing system new lead behaviour.
1) The New Lead Entry screen.
Create a new asp page and call it "Newleadsearch.asp". Copy in the following code and save the file.
<!-- #include file ="accpaccrm.js"-->
<%
if (eWare.Mode==View)
{
eWare.Mode = Edit;
}
//allow entry of a name
//the call a search
//button - carry on and create
//Create Block
var LeadBlock = eWare.GetBlock("EntryGroup");
LeadBlock.Title = eWare.GetTrans("Tabnames","Lead")
LeadBlock.ButtonTitle = "Enter Lead Details";
LeadBlock.ButtonImage = "newlead.gif";
LeadBlock.FormAction = eWare.URL("newleadsearchresult.asp");
var FirstName = eWare.GetBlock("Entry");
with (FirstName)
{
//EntryType set to be single line text entry
EntryType = 10;
DefaultType = 1
FieldName = "lead_personfirstname";
CaptionPos = CapTop;
maxLength = 60;
}
var LastName = eWare.GetBlock("Entry");
with (LastName)
{
//EntryType set to be single line text entry
EntryType = 10;
DefaultType = 1
FieldName = "lead_personlastname";
CaptionPos = CapTop;
maxLength = 60;
}
LeadBlock.AddBlock(FirstName);
LeadBlock.AddBlock(LastName);
eWare.AddContent(LeadBlock.Execute());
Response.Write(eWare.GetPage('new'));
%>
2) The Search Result Page
Create an ASP Page called newleadsearchresult.asp. Copy in the code below and save the file.
<!-- #include file ="accpaccrm.js"-->
<%
var lead_personfirstname = Request.Form("lead_personfirstname");
var lead_personlastname = Request.Form("lead_personlastname");
var Arg = "lead_personfirstname like'"+lead_personfirstname+"%'";
Arg += "and lead_personlastname like '"+lead_personlastname+"%'";
//Retrieve Record
var myRecord = eWare.FindRecord("lead",Arg);
if (myRecord.eof)
{
//no records found
Response.Redirect(eWare.URL(1191)+"&lead_personfirstname="+lead_personfirstname+"&lead_personlastname="+lead_personlastname);
}
else
{
var contentBlock = eWare.GetBlock("content");
contentBlock.contents = "<table id=_icTable width=100% class=InfoContent><tr><td id=_icTD>"+eWare.GetTrans("Information","PersonDedupesDetected")+"</td></tr></table>";
var strEnterButton= eWare.Button("IgnoreEnterPerson","newlead.gif",eWare.URL(1191)+"&lead_personfirstname="+escape(lead_personfirstname)+"&lead_personlastname="+escape(lead_personlastname))
var listBlock = eWare.GetBlock("leadlist");
var myBlockContainer = eWare.GetBlock("Container");
with (myBlockContainer)
{
AddBlock(contentBlock);
AddBlock(listBlock);
DisplayButton(Button_Default) = false;
AddButton(strEnterButton);
}
eWare.AddContent(myBlockContainer.Execute(Arg));
Response.Write(eWare.GetPage("new"));
}
%>
3) The Custom Content Changes
Copy the following code into the custom content box of the leadpersonscreen.
<script>
//This code is to support the New Lead dedupe functionality added by the ASP pages prefixed by "newlead".
//This code should be added to the customcontent box of the lead screen "LeadPersonScreen".
function GetKeyValue(querystringname)
{
var strPath = window.location.search.substring(1);
var arrayKeys = strPath.split("&");
for (var i=0;i<arrayKeys.length;i++)
{
var arrayValue = arrayKeys[i].split("=");
if (arrayValue[0].toLowerCase()== querystringname.toLowerCase())
{
return arrayValue[1];
}
}
return "";
}
window.attachEvent("onload",fillfields);
function fillfields()
{
if (GetKeyValue("lead_personlastname"))
{
document.EntryForm.lead_personlastname.value = GetKeyValue("lead_personlastname");
}
if (GetKeyValue("lead_personfirstname"))
{
document.EntryForm.lead_personfirstname.value = GetKeyValue("lead_personfirstname");
}
}
</script>