Sitecore 9 Dynamic CRM Connector: Create custom facets (Part 1)
Step 1: Create a Visual Studio project
- Create Class Library (.Net Framework) project
- Add below reference from NuGet:
- Sitecore.DataExchange.Tools.DynamicsConnect.NoReferences
- 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.
- Template :Collection Model Folder
- Item Name: Custom Models
- Select the new item.
- Add the following item.
- Template :Compiled Collection Model
- 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:
- yourwebsite.xconnect\App_data\Models
- 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”
Comments
yourwebsite.xconnect\App_data\Models xConnect indexing