0

I would like to create some form of a hierarchy in a Custom Facet in Sitecore 9. However, the documentation only provided examples using Sitecore 8.2 here.

When I tried creating an IElementDictionary in my custom Facet, it says Facet is an ambiguous reference between Sitecore.Analytics.Model.Framework.Facet and Sitecore.XConnect.Facet. Of course, this is due to the former being deprecated. My ModelBuilder also expects an XConnect.Facet in the modelBuilder.DefineFacet method to create the JSON model:

using Caiw.Foundation.XConnect.Models.Facets.Interfaces;
using Sitecore.Analytics.Model.Framework;
using Sitecore.XConnect;
using System;
using System.Collections.Generic;

namespace Caiw.Foundation.Xconnect.Models.Facets
{
    [Serializable]
    [FacetKey(DefaultFacetKey)]
    public class ServiceabilityData : Facet
    {
        public const string DefaultFacetKey = "ServiceabilityData";

        public int HouseNumber { get; set; }

        public string ZipCode { get; set; }

        public string Addition { get; set; }

        public string LocationDescription { get; set; }

        public IElementDictionary<IInfrastructure> Infrastructure { get; }

        public string Street { get; set; }

        public string City { get; set; }

        public string Region { get; set; }

        public string Country { get; set; }

        public string OrderEndpointType { get; set; }

        public int CustomerGroup { get; set; }

        public ServiceabilityData() { }
    }
}

Am I missing something here? How do we extend a hierarchical Facet in Sitecore 9?

2

It's possible to create facets containing Dictionary<K,V> or List<T> properties in 9.1. Facet class needs to derive from Sitecore.XConnect.Facet. See Sitecore's documentation for more information. Here's a sample facet class taken from XConnect's core model:

  [FacetKey("Addresses")]
  [Serializable]
  public class AddressList : Sitecore.XConnect.Facet
  {
    public const string DefaultFacetKey = "Addresses";

    public AddressList(Address preferredAddress, string preferredKey)
    {
      this.PreferredAddress = preferredAddress;
      this.PreferredKey = preferredKey;
    }

    public Dictionary<string, Address> Others { get; set; } = new Dictionary<string, Address>();

    public string PreferredKey { get; set; }

    public Address PreferredAddress { get; set; }
  }
2

Your class ServiceabilityData must be inherits Sitecore.XConnect.Facet. Below is the code:

using Sitecore.XConnect;
using System;
using System.Collections.Generic;

namespace Caiw.Foundation.Xconnect.Models.Facets
{
    [Serializable]
    [FacetKey(DefaultFacetKey)]
    public class ServiceabilityData : Facet
    {
        public const string DefaultFacetKey = "ServiceabilityData";
        public int HouseNumber { get; set; }

        public string ZipCode { get; set; }

        public string Addition { get; set; }

        public string LocationDescription { get; set; }

        //public IElementDictionary<IInfrastructure> Infrastructure { get; }

        public string Street { get; set; }

        public string City { get; set; }

        public string Region { get; set; }

        public string Country { get; set; }

        public string OrderEndpointType { get; set; }

        public int CustomerGroup { get; set; }
        public static explicit operator ServiceabilityData(KeyValuePair<string, Facet> v)
        {
            throw new NotImplementedException();
        }
    }
}
  • Ah yes this is useful when I am about to use the ServiceabilityData as like a Dictionary I think, but the Dictionary property inside this class is what I needed. Thanks for the response! – Bien Angelo Relucano Jun 20 at 5:32

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.