Walkthrough: Extending 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.
Create and customize a model to extend the default List Manager model
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:
-
In Visual Studio, create a project called, for example,
ContactListExtender. -
Create a
ContactDataModelWithPhoneNumberclass that inheritsSitecore.ListManagement.Services.Model.ContactDataModel. -
Add a custom field (for example,
PhoneNumber) to the custom model class.RequestResponsepublic class ContactDataModelWithPhoneNumber:ContactDataModel { [Required, MaxLength(50)] public string PhoneNumber { get; set; } } -
Create a
ListSubscribersWithPhoneNumberMapperclass that inherits theSitecore.ListManagement.Services.Mappers.IListSubscribersMapperinterface. -
Override the
MapSubscribersmethod to return theContactDataModelWithPhoneNumbermodel.RequestResponsepublic 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") ?? contact.Identifiers.FirstOrDefault(); contactDataModel.Identifier = contactIdentifier?.Identifier; contactDataModel.IdentifierSource = contactIdentifier?.Source; contactDataModel.PhoneNumber = contact.GetFacet<PhoneNumber>().Number; return contactDataModel; } -
Create a
CustomServiceConfiguratorclass to replace the default implementation.RequestResponsepublic void Configure(IServiceCollection serviceCollection) { var serviceToRemove = serviceCollection .Where(service => service.ServiceType == typeof(IListSubscribersMapper)) .FirstOrDefault(); serviceCollection.Remove(serviceToRemove); serviceCollection.AddTransient<IListSubscribersMapper, ListSubscribersWithPhoneNumberMapper >(); }
Create a configuration file
Next, you must create a new configuration file to apply the configuration changes.
To create a configuration file:
-
Create a
ContactListExtenderconfig file to apply the configuration changes.RequestResponse<?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"> <services> <configurator type=" ContactListExtender.CustomServiceConfigurator, ContactListExtender" /> </services> <settings> <!-- Adds the PhoneNumber facet to be loaded --> <setting name="ListManagement.Contacts.FacetsToRead" set:value="ListSubscriptions|Personal|Emails|PhoneNumber" /> </settings> </sitecore> </configuration> -
Copy the configuration file to the
<website_path>\App_Config\Includefolder.