5

I'm trying to create a custom facets to insert data into sitecore9 XDB through Xconnect for this, I have followed the blog and XconnectDoc

But when I'm trying to add data into contact custom facet- I'm getting error as The type of this instance does not correspond to any type in the model as shown in the below snapshot. However, I'm able to add facet data into the XDB for the buildin sitecore facets.

enter image description here

Here is the code Snippet for adding data into custom facet along with build in facet

 private static void AddContact()
{
    using (var client = GetClient())
    {
        //Multiple Identifiers can be added as below
        var identifiers = new ContactIdentifier[]
            {
                    new ContactIdentifier("user15", "SSkSudheer15", ContactIdentifierType.Known),
                    new ContactIdentifier("person15", "SSkSuggu15", ContactIdentifierType.Known)
            };

        Contact contact = new Contact(identifiers);
        client.AddContact(contact);

        // Optional thing to add based on the requirement
        PersonalInformation personalInfoFacet = new PersonalInformation()
        {
            FirstName = "Sudheer15",
            LastName = "Suggu15"
        };

        FacetReference reference = new FacetReference(contact, PersonalInformation.DefaultFacetKey);
        client.SetFacet(reference, personalInfoFacet);
        //client.SetFacet<PersonalInformation>(contact, PersonalInformation.DefaultFacetKey, personalInfoFacet);

        EmailAddressList emailFacet = new EmailAddressList(new EmailAddress("Sudheer15@mail.com", true), "email");
        client.SetFacet(contact, emailFacet);

        var carDetails = new CarDetails()
        {
            CarName = "Benz",
            Model = "Mecedes",
            year = 2018
        };
        //FacetReference refernce = new FacetReference(contact, CarDetails.FacetName);
        //client.SetFacet(reference, carDetails);
        //client.SetFacet<CarDetails>(contact, CarDetails.FacetName, carDetails);
        client.SetFacet<CarDetails>(new FacetReference(contact, CarDetails.FacetName), carDetails);
        client.Submit();
    }
}

And the Model code snippet

enter image description here

I have added facet to a custom model and generated json file and dropped it in a different location in Xconnect root folder.

Custom Model code snippet:

 public class XconnectPOCModel
{
    public static XdbModel Model { get; } = BuildModel();
    private static XdbModel BuildModel()
    {
        var builder = new XdbModelBuilder("XconnectPOCCarModel", new XdbModelVersion(1, 0));
        builder.ReferenceModel(Sitecore.XConnect.Collection.Model.CollectionModel.Model);
        builder.DefineFacet<Contact, CarDetails>(CarDetails.FacetName);

        return builder.BuildModel();
    }
}
  • Have you added the facet to a custom model? Have you deployed your model to json and added them in the different places in xconnect? – mark DE Jong Dec 8 '17 at 15:25
  • Yes, I have a facet to a custom model and generate the json file and dropped in the xconnect App_data root locations. – Sudheer Suggu Dec 8 '17 at 15:26
  • Can you post the custom model code? – mark DE Jong Dec 8 '17 at 15:29
  • added code snippet – Sudheer Suggu Dec 8 '17 at 15:31
  • Did you also drop your model dll in this directory? c:\path\to\xconnect\App_data\jobs\continuous\AutomationEngine The custom model seems fine – mark DE Jong Dec 8 '17 at 15:31
4

The error I got in code behind when creating contact, on client.submit() is: "The type of this instance does not correspond to any type in the model". I was currently checking with Sitecore Support team as they found in the logs provided that my custom facet types in the custom model can't be found in Model.Types even they exist there. The solution they provided and helped me was: XdbModel[] models = { CollectionModel.Model, xConnectIntroModel.CollectionModel.Model };

where xConnectIntroModel is my custom model.

Could you please add your custom model variable during initialization, restart Sitecore instance and try again:

 var collectionClient = new CollectionWebApiClient(new Uri(Constants.XConnectDomain.Url + "/odata"), clientModifiers, new[] { certificateModifier });
            var searchClient = new SearchWebApiClient(new Uri(Constants.XConnectDomain.Url + "/odata"), clientModifiers, new[] { certificateModifier });
            var configurationClient = new ConfigurationWebApiClient(new Uri(Constants.XConnectDomain.Url + "/configuration"), clientModifiers, new[] { certificateModifier });

            XdbModel[] models = { CollectionModel.Model, xConnectIntroModel.CollectionModel.Model };

            var config = new XConnectClientConfiguration(new XdbRuntimeModel(models), collectionClient, searchClient, configurationClient);
1

Please try to add the below config patch in the xconnect client config file "App_Config\Sitecore\XConnect.Client.Configuration". ContactCustomerInfoModel is the model that i have created for Custom facet.

<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">
          <schema name="ContactCustomerInfoModel" type="Sitecore.XConnect.Client.Configuration.StaticModelConfiguration,Sitecore.XConnect.Client.Configuration" patch:after="schema[@name='collectionmodel']">
            <param desc="modeltype">MyProject.Feature.Articles.CustomFacets.ContactCustomerInfoModel, MyProject.Feature.Articles</param>
          </schema>
        </schemas>
      </runtime>
    </xconnect>
  </sitecore>
</configuration>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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