2

I want to show custom field value in the contacts list of list manager Sitecore 9.3 enter image description here

FullName and Number are custom fields

2 Answers 2

3

By default, we can only see, First Name, Last Name and email facets values in List Manager view. To extend the contact list view to see custom facets instead of the default ones, you'll need to follow the below steps. I am assuming you've already created and deployed the custom model that wraps a custom facet, as described in this article

  1. Add a column for a custom facet to the Contacts table.
  • Switch to the Core database.
  • Add a new ColumnField item under the /sitecore/client/Applications/List Manager/Lists/Contact list item.
  • Fill out fields, EmptyText (sets a default text if a cell does not contain any data. HeaderText (a name of the column) and DataField (a name of the custom facet, used as a data source).
  • Save the changes. The new column then appears in the List Manager app, but without values.
  1. Create a custom contacts controller.
  • Create your custom ContactDataModel to contain all the required facets.
  • Data is mapped by the Sitecore.ListManagement.Services.Repositories.ListSubscriptionsStoreclass. Create your own class that has a GetSubscribers method returning IEnumerable of your custom model
  • The data is retrieved from _contactProvider and converted to the specified model using the MapEntity method. Next, inject the custom mapping logic in the MapEntity method.
  • The _contactProvider.GetFilteredContacts method returns only three facets (ListSubscriptions, Personal, Emails). So, add the custom ones to the list:
  • The default ListSubscriptionsStore is used by the Sitecore.ListManagement.Services.Controllers.ContactsController controller. Create your custom controller, which performs the same actions and changes the GetEntries method to use the custom ListSubscriptionsStore and Change the RoutePrefix attribute value of the controller to sitecore/api/customlists/{listId}/contacts
  1. Create a processor that registers your control:
    public class RegisterHttpRoutes
        {
            public void Process(PipelineArgs args)
            {
                GlobalConfiguration.Configure(Configure);
            }
     
            protected void Configure(HttpConfiguration configuration)
            {
                var routes = configuration.Routes;
                routes.MapHttpRoute("CustomContacts", "sitecore/api/customlists/{listId}/contacts", new
                {
                    controller = "CustomContacts",
                    action = "customaction", // Name of the action in ActionName attribute         
                });
            }
  1. Patch the RegisterHttpRoutes processor:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
      <sitecore>
        <pipelines>
          <initialize>
            <processor type="Namespace.RegisterHttpRoutes, AssemblyName"/>
          </initialize>
        </pipelines>
      </sitecore>
    </configuration>
  1. Open Core database in the Content Editor and navigate to the /sitecore/client/Applications/List Manager/Global Settings/ListTaskPageSettings/ContactsDataSource Parameters item. Change its URL field to /sitecore/api/customlists.

After performing all these steps, you can upload a CSV list containing custom facets.

You can find all the steps in detail and codebase at my blog post: https://sitecorewithraman.wordpress.com/2021/07/01/customize-list-manager-part-iii/

0

Sitecore 10.2 introduced simpler way of extending list manager with custom fields.

You just need to:

  • create a new class implementing IListSubscribersMapper interface
  • implement MapSubscribers method:
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") ??
         contact.Identifiers.FirstOrDefault();
    contactDataModel.Identifier = contactIdentifier?.Identifier;
    contactDataModel.IdentifierSource =
    contactIdentifier?.Source;
    contactDataModel.PhoneNumber =
    contact.GetFacet<PhoneNumber>().Number;
    return contactDataModel;
}
  • create configurator class
public void Configure(IServiceCollection serviceCollection)
{
     var serviceToRemove = serviceCollection
        .Where(service => service.ServiceType == typeof(IListSubscribersMapper))
        .FirstOrDefault();
     serviceCollection.Remove(serviceToRemove);
     serviceCollection.AddTransient<IListSubscribersMapper, ListSubscribersWithPhoneNumberMapper >();
}
  • register configurator and additional facets in config patch file:
<?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>

Source and more information in Sitecore Documentation here: https://doc.sitecore.com/xp/en/developers/102/sitecore-experience-manager/walkthrough--extending-the-list-manager-to-show-custom-columns-in-a-contact-list.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.