Adding Dedupe Behaviour to the Lead Entity

Hints, Tips and Tricks

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

Adding Dedupe Behaviour to the Lead Entity

  • Comments 7
  • Likes

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>


Comments
  • Is it possible to extend this functionality to the Lead Import routine? I get a lot of queries around this area.

  • Jeff,

    I used this and it's great, however it doesn't account for if you made required fields on the entry group block. If you leave the entry screen blank and submit (even if required) it finds all Lead records. To fix I made the code changes below:

    1) In the New Lead Entry Screen page

    commented out //LeadBlock.FormAction = eWare.URL("newleadsearchresult.asp");

    before eware.addcontent added:

        if (eWare.Mode==Save)

    {

    if (LeadBlock.Validate())

    {

    var lead_personfirstname=Request.Form('pers_firstname');

    var lead_personlastname=Request.Form('pers_lastname');

    Response.Redirect(eWare.URL("newleadsearchresult.asp")+"&pers_firstname="+pers_firstname+"&pers_lastname="+pers_lastname;

    }

    }

    2) In the results page:

    change Request.Form to Request.QueryString.

    var lead_personfirstname = Request.QueryString("lead_personfirstname");

    var lead_personlastname = Request.QueryString("lead_personlastname");

  • Although the article is not new I wonder if there has been a solution for deduplication for the lead Import Routine yet? (like Crampse already asked)

    It is quite time consuming to do this seperately from CRM.

    Thanks in advance for an answer.

  • Will this also address the issue of CRM not finding the correct matching company when opening a new lead?

    Currently CRM does not bring up all the companies that match that lead record, but only the closest match? Can we create Company dedupe rules in the LEAD area?

  • This worked great, but I ran into the problem when the results are more than one list page.  When I click the next page button, it automatically takes me to the new lead page with 'undefined' being passed through as the field values.  Any thoughts on this issue, what can be done to successfully navigate the pages of this list.

    What I have done at the moment is adjust the list size dynamically in the newleadsearchresult.asp file.

    community.sagecrm.com/.../controlling-list-size-in-asp-pages.aspx

  • Danny

    I haven't had the time to revisit this article and its code.  But you can persecute me about it when I am in your offices in December :-)  I will be at you mercy during the partner event.  I am looking forward to seeing you again.

  • For JeffTest please read Jeff Richards!