Skip to main content

Sitecore 9 Dynamic CRM Connector: Create custom facets (Part 1)

Sitecore 9 Dynamic CRM Connector: Create custom facets (Part 1)

crm, crm connector, custom facet, dynamic crm, microsoft dynamic crm, Sitecore


Dynamic CRM Connector will provide you default facets like first name, last name etc. but you can also create custom facets and sync to CRM.

Step 1: Create a Visual Studio project

  • Create Class Library (.Net Framework) project
  • Add below reference from NuGet: 
  1. Sitecore.DataExchange.Tools.DynamicsConnect.NoReferences
  2. Sitecore.XConnect.NoReferences

Step 2: Implementation of Custom facets

  • Create new class to create custom facet “Student” and add following code:
 using Sitecore.XConnect;   
  using System;   
  namespace YourNamespace   
  {   
   [FacetKey(DefaultFacetKey)]   
   [Serializable]   
   public class StudentFacets: Facet   
   {   
    public const string DefaultFacetKey = "Student";   
    public string GraduateYear { get; set; }   
   }   
  }   

Step 3: Implementation of collection model

After creating Custom facets class, you need to create Collection model which define available contact facet.
 using Sitecore.DataExchange.Tools.DynamicsConnect.Models;   
  using Sitecore.XConnect;   
  using Sitecore.XConnect.Schema;   
  namespace YourNamespace   
  {   
   public class StudentModel   
   {   
    public StudentModel()   
    {   
    }   
    static StudentModel()   
    {   
     _model = BuildModel();   
    }   
    private static XdbModel _model = null;   
    public static XdbModel Model { get { return _model; } }   
    private static XdbModel BuildModel()   
    {   
     var builder = new XdbModelBuilder(typeof(StudentModel).FullName, new XdbModelVersion(1, 0));   
     builder.DefineFacet<Contact, StudentFacets>(StudentFacets.DefaultFacetKey);   
     builder.ReferenceModel(DynamicsConnectCollectionModel.Model);   
     return builder.BuildModel();   
    }   
   }   
  }   

Step 4: Deploy the model

  • Build your solution and copy DLL into bin directory of your Sitecore instance.
  • Patch your custom model into \App_Config\Sitecore\XConnect.Client.Configuration\Sitecore.XConnect.Client.config
 <?xml version="1.0"?>   
  <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">   
  <sitecore>   
   <xconnect>   
   <runtime type="Sitecore.XConnect.Client.Configuration.RuntimeModelConfiguration,Sitecore.XConnect.Client.Configuration">   
    <schemas hint="list:AddModelConfiguration">   
    <schema name="StudentModel" type="Sitecore.XConnect.Client.Configuration.StaticModelConfiguration,Sitecore.XConnect.Client.Configuration" patch:after="schema[@name='collectionmodel']">   
     <param desc="modeltype">YourNamespace.StudentModel,AssemblyName</param>   
    </schema>   
    </schemas>   
   </runtime>   
   </xconnect>   
  </sitecore>   
  </configuration>  

Step 5: Add a collection model definition

To define collection model in Sitecore follow below steps:
  • Navigate to this location “/sitecore/system/Settings/Data Exchange/Providers/xConnect/Collection Models”
  • Add the following item.
  1. Template :Collection Model Folder 
  2. Item Name: Custom Models 
  • Select the new item.
  • Add the following item.
  1. Template :Compiled Collection Model 
  2.  Item Name: Custom Collection Model for Dynamics
  • In “Collection Model Type” field set “YourNamespace.StudentModel,AssemblyName”

Step 6: Convert Model to JSON

  • Select Custom Collection Model for Dynamics item
  • To convert Model into Json click on “Convert Model to Json” In the ribbon, it will download model
  • Deploy the model file to the following location:

  1. yourwebsite.xconnect\App_data\Models
  2. yourwebsite.xconnect\App_data\jobs\continuous\IndexWorker\App_data\Models

Step 7: Configure the xConnect Client Endpoint

  • Navigate to this location “/sitecore/system/Data Exchange/XXX/Endpoints/Providers/xConnect/xConnect Client Endpoint”
  • Select “Collection Models/Custom Model/Custom Collection Model for Dynamics” in “Collection Model” field

Step 8: Run Troubleshooter


  • In ribbon, click on “Run Troubleshooter” to ensure that the collection model is deployed and xConnect client endpoint is configured correctly.
  • If everything is OK, it will show popup message that “Connection was successfully established”

Step 9: Verify in Database

  • When you will save custom facets, you can check in DB that custom facets is saving in DB or not. Below are the table name:
  1. [XXX_Xdb.Collection.Shard0].[xdb_collection].[ContactFacets]
  2. [XXX_Xdb.Collection.Shard1].[xdb_collection].[ContactFacets]

In next article, we are going to sync these custom facets with CRM.

Comments

World Citizen said…
Dear Swati, is this folder path a typo?

yourwebsite.xconnect\App_data\Models xConnect indexing
Swati Gupta said…
Thanks for informing, Corrected it.

Popular posts from this blog

Sitecore Certification Sample Questions

Sitecore Certification Sample Questions I have completed the Sitecore 9 certification in 2019 and Sitecore 8.2 Certification in 2018. Let me tell you if you have some knowledge about Sitecore then it will be easier for you to understand questions and clear certification exam. Your main focus should be to understand the questions and answers carefully because it is too confusing There will be two options to give the exam: Install the software in your laptop (Laptop should have mic and webcam) Authorized training Center If you have proper Internet, then you can choose option 1 otherwise option 2 is a good choice. Disclaimer : Please note that the below question is only for information purpose only. Below question does not claim the accuracy of the content. Sample Questions: Question 1: What is the name of Component architecture guideline of Sitecore? Answer : Helix Question 2 : What is horizontal scaling and vertical scaling? Answer :  https://doc.

Sitecore 9 Forms: Google reCaptcha field

Sitecore 9 Forms: Google reCaptcha field  Re-Captcha is the most important part of any form’s submission. Google reCaptcha run internet bot detector and determined whether a user is a bot or not.  Sitecore Forms does not provide Google reCaptcha field, which was available in WFFM before, so I have created my custom Google reCaptcha.   Below you can find step by step process to create Google reCaptcha field. Create patch config for reCaptcha Sitekey and SecretKey <?xml version="1.0"?> <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/"> <sitecore> <settings> <setting name="ReCaptchaSiteKey" value="site-key" /> <setting name="ReCaptchaSecretKey" value="secret-key" /> </settings> </sitecore> </configuration> Create new viewmodel class RecaptchaViewMode

Create Sitecore Custom Admin Page

Create Sitecore Custom Admin Page Sitecore provides you lots of Admin pages just like ShowConfig.aspx, cache.aspx, Logs.aspx, howServicesConfig.aspx, etc. which you can check from here http://<yoursite>/sitecore/admin/. All Sitecore Admin pages is available in this folder “sitecore/admin/*” Sometimes there can be requirement that you want to create custom Admin page which will be accessible to Admin/Non-Admin user. Here is an example: Create aspx page “CustomAdminPage.aspx” inside “<root>/sitecore/admin” folder <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CustomAdminPage.aspx.cs" Inherits="Namespace.CustomAdminPage" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Custom Admin Page</title> <link rel="stylesheet" type="text/css" href="/sitecore/she