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

Azure AD Integration with Sitecore 10.2

 Azure AD Integration with Sitecore 10.2 Sitecore identity server that comes with Sitecore 9.1 allows you to log in through an external identity provider like Azure Active Directory, Facebook, Apple, or Google. It is built on Federation Authentication. What is Federation Authentication? Federation authentication is a technology to allows users to access multiples application, tools, and domains using one credential. Using one set of credential user can access multiple applications, and resources after authentication.  Federation authentication consists of two systems, the Identity provider and the Service provider. Identity providers that maintain/create/manage identity information like name, email address, device, and location. Some examples of identity providers are Azure AD, Google, Facebook, and Apple. Service providers basically refer to a website, software, or app that the user is trying to access and SP basically relies on the identity provider to authenticate the user and provi

Sitecore 10.2 - “Failed to start service ‘Sitecore Marketing Automation Engine’” on Windows 11

Sitecore 10.2 - “Failed to start service ‘Sitecore Marketing Automation Engine' ” on Windows 11 Today I started to install Sitecore 10.2 using Sitecore Instance Manager on Windows 11 and I got this issue “Failed to start service ‘Sitecore Marketing Automation Engine' ” . Error : On event viewer it was showing the below error: I also tried to run ‘ Sitecore.MAEngine.exe ’ like this C:\Windows\system32>C:\inetpub\wwwroot\sclocal102xconnect.dev.local\App_Data\jobs\continuous\AutomationEngine\Sitecore.MAEngine.exe Which was throwing below error: Starting Marketing Automation Engine... 2022-01-29 22:21:11 ERR Error initializing XConnect client. System.AggregateException: One or more errors occurred. ---> Sitecore.XConnect.XdbCollectionUnavailableException: An error occurred while sending the request. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: An unexpected err

Sitecore CDP Certification - Tips and Tricks

Sitecore CDP Certification - Tips and Tricks Recently I completed Sitecore CDP (Customer Data Platform) certification. In this blog, I will share my personal experience and the steps I took to successfully complete the Sitecore CDP certification. Before diving into the certification journey, I researched various resources to plan my preparation effectively: CDP Certificate Competency  Competency 1: Customer Data Platform Competency 2: Real-time Behavior Data Ingestion Competency 3: Interactive API Competency 4: Batch Data Ingestion Competency 5: Audience Sync and Batch Segments Official Documentation https://doc.sitecore.com/cdp/en/users/sitecore-cdp/index-en.html   https://doc.sitecore.com/cdp/en/developers/api/index-en.html#UUID-980f86cc-d900-1d49-3523-030e16d197a2  https://doc.sitecore.com/cdp/ https://learning.sitecore.com/pages/66/sitecore-learning-home CDP & Personalize Mind Map A highly beneficial resource you can discover is the Mind Map . Exam Details The Sitecore CDP Cert