AI agents: the content index is at /llms.txt. Every page is also available as Markdown — send the request header Accept: text/markdown, or append .md to the page URL.
Xperience Docs

Cookie consent

We use necessary cookies (opens in a new tab) to run our website and improve your experience while browsing. Additional cookies are only used with your consent. You may revoke your consent on the Cookies Policy (opens in a new tab) page or in your browser at any time.

Configure (opens in a new tab)
  • Documentation
    InstallationUsing the Xperience interfaceDeveloping websitesConfiguring XperienceManaging usersSecuring websitesDeploying websitesManaging website contentMultilingual websitesMacro expressionsExternal utilitiesIntegrating 3rd party systemsCustom developmentE-commerce featuresOn-line marketing featuresRelease notes - Xperience 13Xperience terminology glossary
  • Tutorial
    Using the Xperience interfaceDeveloper tutorialBusiness tutorialResource hub for marketers
  • API Examples
    ConfigurationContent managementDevelopmentE-commerceOn-line marketingSocial media
  1. Home
  2. On-line marketing
  3. Contact groups

Contact groups


Was this page helpful?

Send us feedback Go back to top
  • Community Questions & Answers (opens in a new tab)
  • Contact support (opens in a new tab)

List of examples:

  • Creating a contact group
  • Updating a contact group
  • Updating multiple contact groups
  • Adding contacts to a contact group
  • Removing contacts from a contact group
  • Adding accounts to a contact group
  • Removing accounts from a contact group
  • Deleting a contact group

Creating a contact group

C#
// Creates a new contact group object
ContactGroupInfo newGroup = new ContactGroupInfo()
{
    ContactGroupDisplayName = "New group",
    ContactGroupName = "NewGroup",
    ContactGroupEnabled = true,
    ContactGroupDynamicCondition = "{%Contact.ContactLastName.Contains(\"Smith\")%}"
};

// Saves the contact group to the database
ContactGroupInfo.Provider.Set(newGroup);
> Back to list of examples

Updating a contact group

C#
// Gets the contact group
ContactGroupInfo updateGroup = ContactGroupInfo.Provider.Get("NewGroup");

if (updateGroup != null)
{
    // Updates the contact group's properties
    updateGroup.ContactGroupDisplayName = updateGroup.ContactGroupDisplayName.ToLowerCSafe();

    // Saves the modified contact group to the database
    ContactGroupInfo.Provider.Set(updateGroup);
}
> Back to list of examples

Updating multiple contact groups

C#
// Gets all contact groups whose name starts with 'New'
var groups = ContactGroupInfo.Provider.Get().WhereStartsWith("ContactGroupName", "New");

// Loops through individual contact groups
foreach (ContactGroupInfo group in groups)
{
    // Updates the contact group properties
    group.ContactGroupDisplayName = group.ContactGroupDisplayName.ToUpper();

    // Saves the modified contact group to the database
    ContactGroupInfo.Provider.Set(group);
}
> Back to list of examples

Adding contacts to a contact group

C#
// Gets the contact group
ContactGroupInfo group = ContactGroupInfo.Provider.Get("NewGroup");

if (group != null)
{
    // Gets all contacts whose last name is 'Smith'
    var contacts = ContactInfo.Provider.Get().WhereEquals("ContactLastName", "Smith");

    // Loops through individual contacts
    foreach (ContactInfo contact in contacts)
    {
        // Creates an object representing the relationship between the contact and the group
        ContactGroupMemberInfo newContactGroupMember = new ContactGroupMemberInfo()
        {
            ContactGroupMemberContactGroupID = group.ContactGroupID,
            ContactGroupMemberType = ContactGroupMemberTypeEnum.Contact,
            ContactGroupMemberRelatedID = contact.ContactID,
            ContactGroupMemberFromManual = true
        };

        // Saves the contact-group relationship to the database
        ContactGroupMemberInfo.Provider.Set(newContactGroupMember);
    }
}
> Back to list of examples

Removing contacts from a contact group

C#
// Gets the contact group
ContactGroupInfo group = ContactGroupInfo.Provider.Get("NewGroup");

if (group != null)
{
    // Gets the first contact whose last name is 'Smith'
    ContactInfo contact = ContactInfo.Provider.Get()
                                        .WhereEquals("ContactLastName", "Smith")
                                        .TopN(1)
                                        .FirstOrDefault();

    // Gets the relationship between the contact and the contact group
    ContactGroupMemberInfo contactGroupMember =
        ContactGroupMemberInfo.Provider.Get(group.ContactGroupID, contact.ContactID, ContactGroupMemberTypeEnum.Contact);

    if (contactGroupMember != null)
    {
        // Removes the contact from the contact group
        ContactGroupMemberInfo.Provider.Delete(contactGroupMember);
    }
}
> Back to list of examples

Adding accounts to a contact group

C#
// Gets the contact group
ContactGroupInfo group = ContactGroupInfo.Provider.Get("NewGroup");

if (group != null)
{
    // Gets the first the account whose name starts with 'New"
    AccountInfo account = AccountInfo.Provider.Get()
                                        .WhereStartsWith("AccountName", "New")
                                        .TopN(1)
                                        .FirstOrDefault();

    // Creates an object representing the relationship between the account and the contact group
    ContactGroupMemberInfo newContactGroupAccountMember = new ContactGroupMemberInfo()
    {
        ContactGroupMemberContactGroupID = group.ContactGroupID,
        ContactGroupMemberType = ContactGroupMemberTypeEnum.Account,
        ContactGroupMemberRelatedID = account.AccountID
    };

    // Saves the account-contact group relationship to the database
    ContactGroupMemberInfo.Provider.Set(newContactGroupAccountMember);
}
> Back to list of examples

Removing accounts from a contact group

C#
// Gets the contact group
ContactGroupInfo group = ContactGroupInfo.Provider.Get("NewGroup");

if (group != null)
{
    // Gets the first the account whose name starts with 'New"
    AccountInfo account = AccountInfo.Provider.Get()
                                        .WhereStartsWith("AccountName", "New")
                                        .TopN(1)
                                        .FirstOrDefault();

    // Gets the relationship between the account and the contact group
    ContactGroupMemberInfo contactGroupAccountMember =
        ContactGroupMemberInfo.Provider.Get(group.ContactGroupID, account.AccountID, ContactGroupMemberTypeEnum.Account);

    if (contactGroupAccountMember != null)
    {
        // Removes the account from the contact group
        ContactGroupMemberInfo.Provider.Delete(contactGroupAccountMember);
    }
}
> Back to list of examples

Deleting a contact group

C#
// Gets the contact group
ContactGroupInfo deleteGroup = ContactGroupInfo.Provider.Get("NewGroup");

if (deleteGroup != null)
{
    // Deletes the contact group
    ContactGroupInfo.Provider.Delete(deleteGroup);
}
> Back to list of examples