Integrating contacts with LinkedIn

Similar to the approach we took in pulling account information from LinkedIn, we can handle the contacts. The difference is, due to the higher probability of having identical names, we can handle this by asking the system user for some additional information.

You could build a more complex solution that queries based on the first, middle, and last names, and returns all matches for the user to select the correct contact; but that would be a next-level solution, and I would probably consider doing it in something other than JavaScript.

In this solution, I will only ask the system user to input the URL to LinkedIn user profile. From there, I will retrieve the required information and bring in a user profile card.

Note

Always check with the data provider to determine if the terms of use allow you to implement this kind of customization in your specific scenario.

Getting ready

In order to build this recipe you will need access to a Dynamics CRM instance, as well as have a system customizer or system administrator permission.

In addition, you should create a solution package if one is not already available.

How to do it...

Within your solution package, take the following steps to customize this:

  1. Add the Contact entity to your solution, if not already added.
  2. Create a new web resource of type JScript. Name it LinkedIn Contact Profile (new_linkedincontactprofile).
  3. Add the following function to your script file:
    function LinkedInGetContactProfile()
    {
      var _contactProfile = Xrm.Page.getAttribute("new_linkedinurl").getValue();
      
      if(_contactProfile != null && _contactProfile != "")
      {
        _contactProfile = _contactProfile.substring(_contactProfile.indexOf("linkedin.com/in/")+16, _contactProfile.length+1);
    
        $("#new_linkedinurl").after(function(){
          var script = '<script src="http://platform.linkedin.com/in.js" type="text/javascript"></script>' +
          '<script type="IN/MemberProfile" data-id="www.linkedin.com/in/' + _contactProfile + 
          '" data-format="inline" data-related="false"></script>';
          return script;
        });
      }
    }
  4. Save and Close the web resource.
  5. Create a new web resource of type JScript. Name it jQuery (new_jquery).
  6. Load the most recent jQuery library you have available.
  7. Save and Close the web resource.
  8. Open the Contact main form for editing.
  9. Add a new one-column section. Label it LinkedIn Profile.
  10. Check the Show the label of this section on the Form and the Show a line at top of the section checkboxes as shown in the following screenshot:.
    How to do it...
  11. Leave the Formatting to One Column.
  12. Click on OK to close this window.
  13. Add a new Text field. Name it LinkedIn URL (new_linkedinurl). Set the Format to URL.
  14. Add the field to the section we created previously.
  15. On the Form Properties, in Form Libraries, add first a reference to the jQuery library.
  16. Then add a reference to the LinkedIn Contact Profile library that contains our function.
  17. In the Event Handlers section, add a reference to your LinkedInGetContactProfile() function to the form OnLoad event.
  18. Click on OK to close the Form Properties window.
  19. In the LinkedIn URL field properties, on the Events tab, add a reference to the same function to the OnChange field event.
  20. Click on OK to close the Field Properties window.
  21. Save and Close the Account form.
  22. In your solution package, click on Publish All Customizations.
  23. In order to test this, first off, let's open a new browser window and run a search for linkedin firstname lastname where firstname and lastname are the names of a contact you are looking for. This will return their public LinkedIn profile page.
  24. The URL format of this page is in the following format:
    http://www.linkedin.com/in/nicolaetarla
  25. Copy this URL into the Contact page in the LinkedIn URL field we created.
  26. Once you tab out of this field, the script will run and the following information card will be displayed on the Contact form:
    How to do it...

How it works...

As mentioned at the beginning of this recipe, in this instance we will have the system user do a little bit of leg work. They have to retrieve the contact's public profile. That is an easy enough task using any search engine available and also greatly simplifies the process of sifting through possible multiple users with the same name.

The first part of the script strips out the member name, which could potentially be used in other scenarios. The second part is the standard code presented in the member profile plugin generator.

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.73.142