Sitecore List Manager – Add Contacts to EXM Lists

This is yet another post on the focal point of Sitecore 8: Contacts. The contact repository is a multi-usage storage of user information, from visitors (named and anonymous) to imported email addresses to be used in email campaigns.

The Sitecore List Manager is a part of EXM (Email Experience Manager) and replaces .NET security roles as segmentation. In Sitecore 8, you do not need a .NET user to send a mail to a person, all you need is a Contact.

To send an email to more than one person you create a list, add Contacts, create an email, select the list and send the email.

My lists - oh what a mess. Don't worry, it's just test data.

My lists – oh what a mess. Don’t worry, it’s just test data.

A ContactList is no more than a Facet on the Contact. The facet contains the GUID of the Contact List Item and a timestamp:

ContactList Facet

ContactList Facet

So because the list is not actually a list but a set of unconnected GUID’s on unconnected Contacts, it is very easy to add and remove users from Contacts (thanks to Michael Sundstrøm for the code):

using System.Collections.Generic;
using Sitecore.Analytics.Model.Entities;
using Sitecore.Analytics.Tracking;
using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.SecurityModel;

namespace MyNamespace
  public class ContactListRepository
    private const string _CONTACT_LIST_TAG_NAME = "ContactLists";

    public IEnumerable<Item> Get(Contact contact, Database database)
      ITag tag = contact.Tags.Find(_CONTACT_LIST_TAG_NAME);

      if (tag == null)
        yield break;

      foreach (ITagValue tagValue in tag.Values)
        yield return database.GetItem(tagValue.Value);

    public void Add(Contact contact, Item listItem)
      using (new SecurityDisabler())
        contact.Tags.Set(_CONTACT_LIST_TAG_NAME, listItem.ID.ToString());

    public void Remove(Contact contact, Item listItem)
      using (new SecurityDisabler())
        contact.Tags.Remove(_CONTACT_LIST_TAG_NAME, listItem.ID.ToString());


So how to Sitecore make these unconnected GUID’s into lists? Each time you add data to the xDB (MongoDB), Sitecore updates the index, Lucene.NET or SOLR. Data is also always queried through the index which is why Sitecore does not need a separate List collection in MongoDB.


About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in c#, Sitecore 8 and tagged , , , , . Bookmark the permalink.

2 Responses to Sitecore List Manager – Add Contacts to EXM Lists

  1. Anders Gjelstrup says:

    Hi Brian.
    Which index is being updated and holds the information about which list(s) a user is added to?
    I have tried to use the import tool “Create list from file”. In my import file I have only users already added as contacts in the database. When I try to create a new list with existing contacts, the dialog after uploading states that only updates are present (which is expected), but afterwards when I expect the rebuilding of the index to take place, it just hangs and no indexing is performed.
    Cannot really understand the reason for this behavior at the moment, but thought that a rebuild of the index related to lists for fixed the issue.
    Have you any experience with this scenario?

  2. briancaos says:

    Anything that is put into xDB is also indexed in the “Analytics” index. Unfortunately, this index cannot be rebuilt manually, your only option is to rebuild your reporting database (which is pretty much a no-go if you have 100GB+ of data in MongoDB).
    I have also experienced locking errors and semi-imported lists, and I know that this is a focus area of Sitecore Support, who should be able to help you out.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s