0

Environment: Sitecore 9.3

I have a list of contacts based on both OOTB and custom facets. When you try to export a list using List Manager, it exports the following fields in CSV file: Identifier, Source, Email, First Name & Last Name.

How to extend the current functionality of List Manager to export the other information related to the Contacts? Other information like Address, Phone Number, etc.

2
1

To add OOTB Facet field to the CSV file:

using Sitecore.ListManagement.XConnect.Web.Export;
using Sitecore.XConnect;
using Sitecore.XConnect.Collection.Model;

namespace YourProject
{
    public class PhoneNumber : IContactDataReader
    {
        public string FacetName => PhoneNumberList.DefaultFacetKey;

        public string Map(Contact contact)
        {
            var phoneNumberList = contact.GetFacet<PhoneNumberList>(PhoneNumberList.DefaultFacetKey);
            string phoneNumber = $"{phoneNumberList.PreferredPhoneNumber.CountryCode}{phoneNumberList.PreferredPhoneNumber.Number}";
            return phoneNumber;
        }
    }
}

To add a Custom Facet field to the CSV file:

using Sitecore.ListManagement.XConnect.Web.Export;
using Sitecore.XConnect;
// Add reference containing definition for Custom Facet

namespace YourProject
{
    public class CustomFacetField : IContactDataReader
    {
        public string FacetName => CustomFacetName.DefaultFacetKey; 

        public string Map(Contact contact)
        {
            var customFacet = contact.GetFacet<CustomFacetName>(CustomFacetName.DefaultFacetKey);
            string customFacetFieldName = customFacet.CustomFacetFieldName;
            return customFacetFieldName;
        }
    }
}

The final step is to patch the App_Config/Sitecore/ListManagement/Sitecore.ListManagement.config with your own config file.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <listManager>
      <export>
        <field name="PhoneNumber" type="YourProject.PhoneNumber, YourProject" />
        <field name="CustomFacetField" type="YourProject.CustomFacetField, YourProject" />
      </export>
    </listManager>
  </sitecore>
</configuration>

For detailed explanation, check out this article.

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.