0

xConnect Custom Facet is throwing an error while getting the contact contact.GetFacet call. We had followed all the steps from this article https://sitecoreamateurs.wordpress.com/2020/08/31/sitecore-9-xconnect-how-to-create-custom-contact-facet/.

The facet is saved but we cannot get the facet and we also see the same error in the interactions table events column JSON and may be even saving is failed partially.

Contact contact = client.Get < Contact > (new IdentifiedContactReference("CRM", "42012573"), new ContactExpandOptions(PersonalInformation.DefaultFacetKey, CustomInfoFacet.DefaultFacetKey));

if (contact == null) {
    client.AddContact(contact);
}

var facet = contact.GetFacet < CustomInfoFacet > (CustomInfoFacet.DefaultFacetKey);

Events Column in the interations. enter image description here

enter image description here

3
  • what is DiaUserInfoFacet.DefaultFacetKey in your example. It should be replaced with your registered custom facet key. CustomInfoFacet.DefaultFacetKey. So to get contact:var facet = contact.GetFacet < CustomInfoFacet > (CustomInfoFacet.DefaultFacetKey); Mar 10, 2021 at 4:53
  • @RamanGupta While writing the above post I made a typo and I have corrected the above description. The call is CustomInfoFacet.DefaultFacetKey only
    – SNew
    Mar 10, 2021 at 12:31
  • can you verify that you have add all the configuration in your patch file that mentioned here
    – Nithya
    Aug 13, 2021 at 5:29

1 Answer 1

1

To create the Custom facets in Sitecore you need to perform the below-mentioned steps:

  1. Create a Custom Facet Model
  2. Register the Custom Facet Model
  3. Deploy custom Facet model to XDB
  4. Add Custom Facet Model to Configuration

Reference of the Contact should be the same, it should not be like one variable created from Sitecore.Analytics.tracking.contact and another is from Sitecore.Xconnect.Contact. It should be with Sitecore.XConnect.Contact.

For more details about How to create Custom Facet refer to blog post: Create Custom Facet in Sitecore

Above mentioned steps will only create your Custom Facet. Once you complete the creation of Custom Facets you can play with it like set and update facets.

Before getting the facet, first set the facet values. You need to use client.SetFacet() method to set or update facet.

For more details about How to set/update or get facets to refer to blog-post: Work with Custom Facet in Sitecore

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.