Login / Register  search  syndication  about

          Kris Halsrud's Blog

Kris Halsrud on development and Integration with CRM and Development

Converting a Lead to Contact and passing acrossed custom fields

When a Lead is converted to a Contact in the SalesLogix web client, the Lead information is passed across to the contact that is created.  The logic for this data transfer occurs in several entity level business rules at the Lead entity.   There are several rules involved including: ConvertLeadToAccount, ConvertLeadToContact, ConvertLeadAddressToAccountAddress, and ConvertLeadAddressToContactAddress.  These rules are all named pretty logically, as to there purpose.  These rules are all implemented withing the compiled Sage.SalesLogix.BusinessRules.dll assembly and therefor cannot be modified. Also, within that assembly are several private helper methods that are also not exposed for use or modification.

Since the core area can't be modified how would you add logic to transfer custom fields from the Lead area to the Contact area?

Well lets take a step back and look at where the business rules are actually called from.  This logic is all invoked when you convert a lead to a contact which takes place from the custom smart part called  LeadSearchAndConvert.ascx with a corresponding code file of LeadSearchAndConvert.ascx.cs.  These smart parts are located in the VFS under Portal Manager...Sage SalesLogix...Support Files...SmartParts...Lead.  The relevant parts are all in the LeadSearchAndConvert.ascx.cs file, specifically in the methods called  ConvertLeadToNewAccountandContact, and ConvertLeadToContact.  The methods are called based on whether the lead is being added to an existing Account during the conversion.  If we look at the ConvertLeadToNewAccountandContact method (both are fairly similar so we should be able to see what we are talking about) we see the following:

 private void ConvertLeadToNewAccountAndContact(ILead lead, bool createOpportunity, string options)
    {
        IOpportunity opportunity = null;
        IContact contact = EntityFactory.Create<IContact>();
        IAccount account = EntityFactory.Create<IAccount>();
        string leadHistoryId = string.Empty;
        ILeadHistory leadHistory = null; EntityFactory.Create<ILeadHistory>();
        leadHistoryId = lead.SaveLeadHistory();

        lead.ConvertLeadToContact(contact, account, options);
        lead.ConvertLeadToAccount(account);
        lead.ConvertLeadAddressToAccountAddress(account);
        lead.ConvertLeadAddressToContactAddress(contact);
        account.Save();
        contact.SaveContactAccount(account);

This is only the beginning of the method but shows us the important parts.  Specifically, in code a new Account and Contact entity are established (The first 2 highlighted lines).  Then the lead business rules are called (the second set of highlighted lines).

Now that we see how the rules are called we have two options.  One would be to add our code right to these methods in the LeadSearchAndConvert.ascx.cs file. We could do that by adding code like shown highlighted here: 

    private void ConvertLeadToNewAccountAndContact(ILead lead, bool createOpportunity, string options)
    {
        IOpportunity opportunity = null;
        IContact contact = EntityFactory.Create<IContact>();
        IAccount account = EntityFactory.Create<IAccount>();
        string leadHistoryId = string.Empty;
        ILeadHistory leadHistory = null; EntityFactory.Create<ILeadHistory>();
        leadHistoryId = lead.SaveLeadHistory();

        lead.ConvertLeadToContact(contact, account, options);
        lead.ConvertLeadToAccount(account);
        lead.ConvertLeadAddressToAccountAddress(account);
        lead.ConvertLeadAddressToContactAddress(contact);
        contact.CustomProperty = lead.CustomProperty;
        contact.CustomProperty2 = lead.CustomProperty2;
        contact.CustomProperty3 = lead.CustomProperty3;
        account.Save();
        contact.SaveContactAccount(account);

Adding this code will alter the Contact entity that has been established and then populated via the Lead business rules.  Placing our code where it is puts it after the Business Rules run and before the Account and Contact entities are actually saved.

As an alternative to this we could modify the business Rules themselves, adding a Post Execute event.  You can see the business rules have some input parameters.  For instance the ConvertLeadToContact rule passes in three parameters, an instance of the account, contact, and options objects.  That means from within the business rule you could add the exact same set of code we added directly to the user control code file:

    contact.CustomProperty = lead.CustomProperty;
    contact.CustomProperty2 = lead.CustomProperty2;
    contact.CustomProperty3 = lead.CustomProperty3;

 Either way will allow your custom Lead data to pass across to the Contact that is spawned from the Lead upon Conversion.  Of course you can extend this in other ways to besides just one to one field mappings.  With an understanding of where and how the conversion happens, the rest is up to you.

What's This?
  
Bookmark and Share

About Kris Halsrud

   Kris Halsrud is a Senior Analyst / Developer for Customer FX Corporation.


Related Content
   Changing the Default Operator in the SalesLogix Lookup Control in the SalesLogix 7.5.4 Web Client
In the SalesLogix web client, the Lookup Control is a custom composite control that is contained in a com
Posted on May 15, 2012 by Kris Halsrud to Kris Halsrud's Blog
 
   Building a Simple Solution in SalesLogix Web Workshop Video
If you missed this workshop... ...You can watch the video! Learn how to build a simple project managem
Posted on May 09, 2012 by Brianna Tinjum to SalesLogix Product Blog
 
   Step by step guide to creating an Account filter on RegionalManagerID in the 7.5.4 SalesLogix Web client
The SalesLogix web client there is a standard account filter for Account Manager that allows you to filte
Posted on May 03, 2012 by Kris Halsrud to Kris Halsrud's Blog
 
   A realy cool nugget- How to show and hide tabs dynamically in the SalesLogix Web Client
In the SalesLogix LAN client and web client one of the most requested thing I am asked is how do you hide
Posted on May 01, 2012 by Kris Halsrud to Kris Halsrud's Blog
 
   Error accessing components in the VirtualFileSystem in SalesLogix Application Architect
 I recently ran into an issue on a VFS under GIT source control where I had checked out a different
Posted on Apr 26, 2012 by Kris Halsrud to Kris Halsrud's Blog
 
Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add
All contents Copyright © 2012 Customer FX Corporation
Customer FX Corporation
2324 University Avenue West, Suite 115
Saint Paul, Minnesota 55114
Tel: 800.728.5783

  Follow @CustomerFX on twitter
Follow the best news, tips, and articles
  Subscribe to Customer FX on youtube
Watch SalesLogix tutorial videos from Customer FX
Login / Register