3

I'm trying to extend an existing import mapper to include custom contact facets.this is the code I used following the documentation of sitecore 9.1 https://doc.sitecore.com/users/91/sitecore-experience-platform/en/configure-the-import-contacts-wizard-to-include-custom-contact-facets.html

this is my new class that represents the new extended mapper:

namespace CustomFacet
{
    public class ExtendedEmailFacetMapperSample : IFacetMapper
    {
        private readonly PreferredEmailFacetMapper mapper;
        // Decorate the existing PreferredEmailMapper
        public ExtendedEmailFacetMapperSample(
          PreferredEmailFacetMapper mapper)
        {
            this.mapper = mapper;
        }
        public MappingResult Map(string facetKey, Sitecore.XConnect.Facet facet, ContactMappingInfo mappings, string[] data)
        {
            // Call the existing email mapper to map all the basic email fields
            var result = this.mapper.Map(facetKey, facet, mappings, data);
            var facetMappedResult = result as FacetMapped;
            if (facetMappedResult == null)
            {
                return result;
            }
            var partiallyMappedFacet = facetMappedResult.Facet as EmailAddressList;
            if (partiallyMappedFacet == null)
            {
                return result;
            }
            // Set Personal email
            var personalEmail = mappings.GetValue("PersonalEmail", data);
            if (!string.IsNullOrWhiteSpace(personalEmail))
            {
                partiallyMappedFacet.Others["Personal"] = new EmailAddress(personalEmail, false);
            }
            // Set Work email
            var workEmail = mappings.GetValue("WorkEmail", data);
            if (!string.IsNullOrWhiteSpace(workEmail))
            {
                partiallyMappedFacet.Others["Work"] = new EmailAddress(workEmail, false);
            }
            return result;
        }
    }
}

and then I Registered the facet mapper in the Sitecore.ListManager.config file under the sitecore/import/facetMapper section:

<facetMappers hint="list:Add">
  <facetMapper type="Sitecore.ListManagement.XConnect.Web.Import.ListSubscriptionMapper, Sitecore.ListManagement.XConnect.Web" />
  <facetMapper type="Sitecore.ListManagement.XConnect.Web.Import.PreferredAddressFacetMapper, Sitecore.ListManagement.XConnect.Web" />
  <facetMapper type="Sitecore.ListManagement.XConnect.Web.Import.PreferredEmailFacetMapper, Sitecore.ListManagement.XConnect.Web" />
  <facetMapper type="Sitecore.ListManagement.XConnect.Web.Import.PersonalInformationFacetMapper, Sitecore.ListManagement.XConnect.Web" />
  <facetMapper type="CustomFacet.ExtendedEmailFacetMapperSample, CustomFacet">
    <param type="Sitecore.ListManagement.XConnect.Import.PreferredEmailFacetMapper, Sitecore.ListManagement.XConnect" />
  </facetMapper> 
</facetMappers>

but it results in this exception :

Exception Sitecore.Exceptions.ConfigurationException: Could not create instance of type: CustomFacet.ExtendedEmailFacetMapperSample. No matching constructor was found.
1

Looks like the param which you are passing

<param type="Sitecore.ListManagement.XConnect.Import.PreferredEmailFacetMapper, Sitecore.ListManagement.XConnect" />

is not in the assembly Sitecore.ListManagement.XConnect, it's located in the assembly Sitecore.ListManagement.XConnect.Web

Just update the config as

      <facetMappers hint="list:Add">
          <facetMapper type="Sitecore.ListManagement.XConnect.Web.Import.ListSubscriptionMapper, Sitecore.ListManagement.XConnect.Web" />
          <facetMapper type="Sitecore.ListManagement.XConnect.Web.Import.PreferredAddressFacetMapper, Sitecore.ListManagement.XConnect.Web" />
          <facetMapper type="Sitecore.ListManagement.XConnect.Web.Import.PreferredEmailFacetMapper, Sitecore.ListManagement.XConnect.Web" />
          <facetMapper type="Sitecore.ListManagement.XConnect.Web.Import.PersonalInformationFacetMapper, Sitecore.ListManagement.XConnect.Web" />
           <facetMapper type="CustomFacet.ExtendedEmailFacetMapperSample, CustomFacet">
            <param type="Sitecore.ListManagement.XConnect.Web.Import.PreferredEmailFacetMapper, Sitecore.ListManagement.XConnect.Web" />
          </facetMapper>

      </facetMappers>

Update - PreferredEmailFacetMapper is located in the namespace Sitecore.ListManagement.XConnect.Web.Import so updated the type as well.

  • I tried to replace <param type="Sitecore.ListManagement.XConnect.Import.PreferredEmailFacetMapper, Sitecore.ListManagement.XConnect.Web" /> but it results this exception :Exception System.Exception: Could not resolve type name: Sitecore.ListManagement.XConnect.Import.PreferredEmailFacetMapper, Sitecore.ListManagement.XConnect.Web (method: Sitecore.Configuration.DefaultFactory.CreateFromTypeName(XmlNode configNode, String[] parameters, Boolean assert)). – Mariam Nasr Mar 3 at 11:09
  • Updated the type for the PreferredEmailFacetMapper.. Use the above updated config.. The Sitecore documentation needs to be updated, the below link shows the old dll and type name for PreferredEmailFacetMapper doc.sitecore.com/users/91/sitecore-experience-platform/en/… – Gobinath Mar 5 at 20:47

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.