Walkthrough: Extending the List Manager to show custom columns in a Contact list


How to extend the List Manager to show custom columns in a Contact list.

To see specific contact facet data, you can customize the columns that are displayed in a Contact list. This is useful when you want to have additional columns (such as Phone and City for example) in the Contact list table. By default, the Contact list table contains only Email, First Name, and Last Name.

This walkthrough describes how to:

  • Create and customize a model to extend the default List Manager model

  • Create a new configuration file

After you complete this walkthrough, you must also add a column to the Contact list to display the custom facet.

Start by creating a new project to store your model and then customize your new model to extend the default List Manager model.

To create and customize a model to extend the default List Manager model:

  1. In Visual Studio, create a project called, for example, ContactListExtender.

  2. Create a ContactDataModelWithPhoneNumber class that inherits Sitecore.ListManagement.Services.Model.ContactDataModel .

  3. Add a custom field (for example, PhoneNumber) to the custom model class.

    public class ContactDataModelWithPhoneNumber:ContactDataModel
         [Required, MaxLength(50)]
         public string PhoneNumber { get; set; }
  4. Create a ListSubscribersWithPhoneNumberMapper class that inherits the Sitecore.ListManagement.Services.Mappers.IListSubscribersMapper interface.

  5. Override the MapSubscribers method to return the ContactDataModelWithPhoneNumber model.

    public ContactDataModel MapSubscribers(Contact contact)
         var contactDataModel = new ContactDataModelWithPhoneNumber
            Id = (contact.Id ?? Guid.Empty).ToString()
    contactDataModel.Email = contact.Emails()?.PreferredEmail?.SmtpAddress;
    contactDataModel.FirstName = contact.Personal()?.FirstName;
    contactDataModel.LastName = contact.Personal()?.LastName;
    var contactIdentifier = contact.Identifiers.FirstOrDefault(x=> x.Source == "ListManager") ??
    contactDataModel.Identifier = contactIdentifier?.Identifier;
    contactDataModel.IdentifierSource =
    contactDataModel.PhoneNumber =
    return contactDataModel;
  6. Create a CustomServiceConfigurator class to replace the default  implementation.

    public void Configure(IServiceCollection serviceCollection)
         var serviceToRemove = serviceCollection
            .Where(service => service.ServiceType == typeof(IListSubscribersMapper))
         serviceCollection.AddTransient<IListSubscribersMapper, ListSubscribersWithPhoneNumberMapper >();

Next, you must create a new configuration file to apply the configuration changes.

To create a configuration file:

  1. Create a ContactListExtender config file to apply the configuration changes.

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration xmlns:set="http://www.sitecore.net/xmlconfig/set/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
      <sitecore role:require="Standalone or ContentManagement">
            <configurator type=" ContactListExtender.CustomServiceConfigurator, ContactListExtender" />
    	  <!-- Adds the PhoneNumber facet to be loaded  -->
              <setting name="ListManagement.Contacts.FacetsToRead" set:value="ListSubscriptions|Personal|Emails|PhoneNumber" />
  2. Copy the configuration file to the <website_path>\App_Config\Include folder.