Monday, 10 June 2013

mscrm_facebook integration : Display Contact picture from Facebook in mscrm


http://blogs.msdn.com/b/crm/archive/2011/09/28/displaying-a-contact-s-facebook-picture-in-microsoft-dynamics-crm-2011.aspx

This Entire Integration is based on 0nly one URL and that is,
As you may Know, Each and Every User in Facebook has an Unique ID, Some change them into Alphabets called
“your Facebook URL” you can do this in Facebook Setting, and some leave as Numbers.
This User’s Facebook URL can be Generally fall in Users First and Last name, as follows
So, Most of the Organizations Collect First and Last name while creating a contact.
If you use
http://graph.facebook.com/userid/picture?type=large  //Large size picture
http://graph.facebook.com/userid/picture?type=small // Small size picture
http://graph.facebook.com/userid/picture?type=normal // Normal size Picture
the above url Displays users Profile Picture separately without any other user Information.
Now. we come to CRM,
Create a new CRM webresource javascript type and paste the following code.
function pp()
{
var profilepicture = Xrm.Page.getControl(“WebResource_profile”);
// ”WebResource_profile” Name of the other web resource which you place in the form to display the Picture. 
if (!profilepicture)
{
return;
}
//Get the first and lat name of the Contact
var fn = Xrm.Page.data.entity.attributes.get(“firstname”).getValue();
var ln = Xrm.Page.data.entity.attributes.get(“lastname”).getValue();
var fin = fn+ln; // Concatenate the First and last name without space.
var furl = ”http://graph.facebook.com/” + fn + “/picture?type=large”;
//Then set the finalized URL as the Source for the web-resource placed in the Form.
profilepicture.setSrc(furl);
}
The Above Code downloads the Large picture from contact’s Facebook account.
Now, Customize the Entity Form by adding a new webresource, with some common profile picture as default.
add the JavaScript webresource with any message you want, onload, OnSave or Onchange of the Form method.
you can also further redesign the code by inserting a new field for facebookID and pass the data directly in to URL, in this case the CRM user must know the contacts FacebookID to Display the Picture.
I do know that the resultant picture is not 100% accurate and not reliable.
But I hope this code can be further developed which might enable the CRM users to search the Contacts in facebook and Save the Desired Picture from the result.