Integrate Social channels other than Facebook and Twitter to automatically create record in Dynamics CRM

The world ‘social’ has become so trendy these days that just the term makes any subject interesting. And CRM being an application with Myriad of possibilities, it cannot escape itself from the social media integration as well.

So here was my customer embracing the integration of dynamics CRM with Social listening. They were amazed by the feature of creating a record in CRM dynamically from the Social listening window. However the problem is CRM social listening allows you to create records from Facebook and twitter only. And here they were interested in some other social channel.

And yes we did it. And since there are very less blogs on this which describes the custom integration end-end, I thought of penning it down step by step. Since I cannot copy-paste the entire code for my customer here, I would take an example here to explain the whole scenario.

  • The first step is to go in CRM and add the Social Channel integration you are looking for. By default, Facebook and Twitter is already there. I will add ‘Custom Channel’ as well.
    • Go to customizations –> Social Activity –> Fields
    • Open the field with schema name – “community”.
    • image
    • Click on Edit and add the new social channel. I added ‘custom channel. Note the value of optionset item. You will need this. For myself, I have given it a value of “4”.
  • The next step is to create a Social Profile for Social Channel. However every social profile need to be associated with a contact or an account in CRM. So first I will go ahead and create a contact in Dynamics CRM for the LinkedIn social profile.

image

  • Now we have to create the social profile in Dynamics CRM. Unfortunately we cannot create the social profile through UI. Below is the sample code to create a social profile associated to a contact.

var socialProfile = new Entity("socialprofile");
socialProfile["community"] = new OptionSetValue(4);
socialProfile["profilename"] = "Social Profile for Custom Social Channel";
socialProfile["customerid"] = new EntityReference("contact", Guid.Parse("BFCDE148-1306-E611-80E2-6C3BE5A8B1D0"));

crmService.Create(socialProfile);

The guid in the above is the guid of the contact we created just before. And community field has value of 4 which is what we created for Custom Social Channel.

So you are all set. Now the next obvious step is to create the social activity record. Not so fast! There is one big step missing and that is the ‘Automatic record creation and update rules’ set-up. This step is to basically tell CRM what to do when a social activity of type of Custom Social Channel is getting created.

  • Go to Settings –> Service Management –> Automatic Record Creation and Update Rules

image

  • Create a new rule. Off-course you will give a different name and stuffs to this.

image

  • Notice carefully the screenshot above. There is a lookup for additional properties. This is the most important part. I have created a record named ‘Custom Channel Properties’ and associated here. Below is the screenshot for the record.

image

Notice the Channel properties sub-grid in the above screenshot. You have to define only those properties here which would come from the json feed from the social channel you have chosen. The property names should be exact match. Please note that for an example here, I would create a contact record from the social channel feed. So I have defined three properties firstname, lastname and emailaddress

The next step is to specify when this rule will take effect and what it should do. For this we have to specify the record creation and update Details. Add a new record to the sub-grid as shown in the below screenshot.

image

Here I specified that if the source of this activity is my custom channel then create a contact record. The contact record fields are populated from the channel properties that we defined earlier.

image

Save and close and activate the rule. All set and done. Now the last step is to create the social activity record.

Here I will not demo the code to get the JSON from the social channel you are integrating with because it depends on the API of the respective social channel. I will assume that you have got the json feed. With that I will show the sample code below to create a social activity.

var ent = new Entity("socialactivity");
           ent["activityadditionalparams"] = "{firstname: \"Social\", lastname: \"Contact\", emailaddress:\"social@linkedin.com\"}";
           ent["subject"] = "From Social channel";
           ent["community"] = new OptionSetValue(4);
           ent["postfromprofileid"] = new EntityReference("socialprofile", Guid.Parse("0B994E58-0206-E611-80E2-6C3BE5A83B1C"));

           service.Create(ent);

The most important line in the above code is highlighted in bold. Here we are passing the json feed in a special field of social activity record called ‘activityadditionalparams’. Notice that I mentioned the same json properties that I specified in the channel properties. CRM will do the task for you to map it from the json output to the channel properties.

And voila! Once I run the above code, I go to my contacts list and can see the contact created.

Hope this helps!

Advertisements

Author: Debajit

I am a Dynamics CRM Most Valuable Professional (MVP) with 10 years of experience in Microsoft .NET Technologies and 7 years of dedicated experience in Microsoft Dynamics CRM. I have worked with companies like Microsoft, SanDisk, PwC, TMF Group and have extensive experience of implementing complex CRM solutions from both offshore and client side. Currently the face of XrmForYou.com with significant experience in delivering corporate training on Dynamics CRM and have already delivered multiple projects to client through XrmForYou.com Author of multiple tools on codeplex including the 'Role Based Views' and 'CRM-Sharepoint Metadata manager & Attachment Extractor' which are available for commercial use under XrmForYou.com For consulting/ training, drop me a note at info@xrmforyou.com or visit our website www.xrmforyou.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s