3

I am trying to create custom facets on new contacts.

I am using this code :

        using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
        {
            var model = client.Model;
            Contact contact = new Contact(new ContactIdentifier("external", Guid.NewGuid().ToString(), ContactIdentifierType.Known));
            client.AddContact(contact);


            MyConsumerProfileFacet facet = new MyConsumerProfileFacet ();
            facet.Email = "[email protected]";
            facet.LastName = "aaaaaaaa";
            facet.FirstName = "bbbbbbb";

             client.SetFacet(contact, MyConsumerProfileFacet .DefaultFacetKey, facet);

            client.Submit();

        }

On submit I have next exception : The type of this instance does not correspond to any type in the model

On xConnect I deployed my json model and it looks like :

"Types": {
    "X.Feature.DynamicsCrm.Facets.ConsumerProfileFacet": {
      "Type": "Facet",
      "BaseType": "Sitecore.XConnect.Facet",
      "ClrType": "X.Feature.DynamicsCrm.Facets.ConsumerProfileFacet, X.Feature.DynamicsCrm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
      "Properties": {
        "Websitegroup": {
          "Type": "String"
        },
        "Subscribetoportalnews": {
          "Type": "String"
        },
        "Subscribetoportalemail": {
          "Type": "String"
        },
        "Subscribetoportalblog": {
          "Type": "String"
        }, 
         "Email": {
      "Type": "String"
        }, 
       // other properties 
       }
   }

If I used default Facets it works perfectly.

What I am doing wrong ?

3
  • Can you also post custom facet c# class? Have you patched also XConnect.Client with your custom facet? See last chapter of this article doc.sitecore.net/developers/xp/xconnect/xconnect-model/… . We had similar issue and this solved it Jun 5, 2018 at 8:07
  • @PeterProchazka please add your answer, I just added my model into a config file and it works. I had before this issue but I forgot about it.. . Jun 5, 2018 at 8:22
  • Glad I could help you Vlad. It was lucky shot or good gut feeling... ;) Jun 5, 2018 at 9:12

1 Answer 1

7

You need to add your custom model into config file which will patch \App_Config\Sitecore\XConnect.Client.Configuration\Sitecore.XConnect.Client.config at the end.

Something similar to this code:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
    <xconnect>
    <runtime type="Sitecore.XConnect.Client.Configuration.RuntimeModelConfiguration,Sitecore.XConnect.Client.Configuration">
        <schemas hint="list:AddModelConfiguration">
            <!-- value of 'name' property must be unique -->
            <schema name="documentationmodel" type="Sitecore.XConnect.Client.Configuration.StaticModelConfiguration,Sitecore.XConnect.Client.Configuration" patch:after="schema[@name='collectionmodel']">
                <param desc="modeltype">Documentation.Model.CollectionModel, Documentation.Model</param>
            </schema>
        </schemas>
    </runtime>
    </xconnect>
</sitecore>
</configuration>

More information can be found here: https://doc.sitecore.net/developers/xp/xconnect/xconnect-model/managing-model/deployment.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.