LinkedIn Integration with Dynamics CRM 4.0 Accounts

Paul Nieuwelaar, 08 September 2010

A few days ago I was reading a post by Marco Amoedo, where I found a very easy to use LinkedIn connector for the Microsoft Dynamics CRM 4.0 Accounts. By adding a few lines of code to the Account forms onload you are able to make a LinkedIn icon appear beside the account name once it has been saved, which when clicked will search LinkedIn for the account name, and show how many people work there, and will allow you to click on the name to open the account in LinkedIn.

The code to use this is very easy, and it should work unchanged. Copy and paste the following code from http://marcoamoedo.com/ into the Accounts onLoad event, making sure ‘Event is enabled’ is checked.

function LinkedInLoader(crmFormField) {

    var ll = this;

    ll.scriptSource = 'http://www.linkedin.com/companyInsider?script&useBorder=yes'

    ll.field = crmFormField;

    ll.container = crmFormField.parentNode;

    ll.nameToSearch = crmFormField.DataValue;

    ll.spanId = ll.field.id + '_linkedin';

 

    if (ll.container != null) {

        var span = document.createElement('span');

        span.id = ll.field.id + '_linkedin';

 

        var td1 = document.createElement('td');

        td1.innerHTML = ll.container.innerHTML;

 

        var td2 = document.createElement('td');

        td2.appendChild(span);

        td2.style.width = '15px';

 

        var tr = document.createElement('tr');

        tr.appendChild(td1);

        tr.appendChild(td2);

 

        var table = document.createElement('table');

        table.width = '100%';

        table.style.tableLayout = 'fixed';

        table.cellSpacing = 0;

        table.cellPading = 0;

        table.appendChild(tr);

 

        ll.container.innerHTML = table.outerHTML;

    }

 

    ll.ApplyCorrections = function () {

        var div = document.getElementById('company-insider-info-window');

        if (div != null) div.style.height = '275px';

        else window.setTimeout(ll.ApplyCorrections, 500);

    }

 

    ll.Enable = function () {

        new LinkedIn.CompanyInsiderPopup(ll.spanId, ll.nameToSearch);

        new LinkedIn.CompanyInsiderStylesheet();

        var span = document.getElementById(ll.spanId);

        if (span != null) span.attachEvent('onclick', ll.ApplyCorrections);

    }

 

    ll.OnScriptReadyState = function () {

        if ((event.srcElement.readyState == 'complete') || (event.srcElement.readyState == 'loaded')) {

            ll.Enable();

        }

    }

 

    ll.Load = function () {

        var script = document.createElement('script');

        script.type = 'text/javascript';

        script.src = ll.scriptSource;

        script.onreadystatechange = ll.OnScriptReadyState;

        document.getElementsByTagName('head')[0].appendChild(script);

    }

}

 

if (crmForm.FormType != 1) {

    // Set the field that contains the company name

    var linkedInLoader = new LinkedInLoader(crmForm.all.name);

    linkedInLoader.Load();

}

But as you may have noticed in the image at the top of the post, Account Name is Business Recommended, and that means you can save the form without filling in the Account Name, which would still make the LinkedIn icon appear, even though there is no Account Name.

So just in case Account Name isn’t Required, what you can do is change the line highlighted to look like this:

if (crmForm.FormType != 1 && crmForm.all.name.DataValue != null) {

Now the LinkedIn icon will only appear when the form has been saved, and Account Name contains data.

As I said earlier this code should work unchanged, but in case you have a different field you want to use it on, just change both instances of “name” to the field name.

Thanks again to http://marcoamoedo.com for providing the solution!