web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Retrieve members of a Static marketing list

(0) ShareShare
ReportReport
Posted on by

Hi,

I need to retrieve members of a marketing list but i have no idea how?

Thank you for all answers.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    There are two types of marketing lists:

    1. Static- serach in listmember entity using listid.

    2. Dynamic- you will get the fetchxml inside query attribute of the dynamic marketing list. use this fetchxml to get the member list.

  • Community Member Profile Picture
    on at

    Ok, I need to retrieve members of a static MA List. 

    Thank you for your answer

  • Suggested answer
    Rajat Awasthi Profile Picture
    675 on at

    Hi Guy ,

    You can do this using below code:-

    private void GetAllMembers_Click(object sender, EventArgs e)

    {

    ArrayList memberGuids = new ArrayList();

    IOrganizationService orgService = GetOrganizationService();

    PagingInfo pageInfo = new PagingInfo();

    pageInfo.Count = 5000;

    pageInfo.PageNumber = 1;

    QueryByAttribute query = new QueryByAttribute("listmember");

    // pass the guid of the Static marketing list

    query.AddAttributeValue("listid", new Guid("2CA7881F-3EDA-E111-B988-00155D886334"));

    query.ColumnSet = new ColumnSet(true);

    EntityCollection entityCollection = orgService.RetrieveMultiple(query);

    foreach (Entity entity in entityCollection.Entities)

    {

    memberGuids.Add(((EntityReference) entity.Attributes["entityid"]).Id);

    }

    // if list contains more than 5000 records

    while (entityCollection.MoreRecords)

    {

    query.PageInfo.PageNumber += 1;

    query.PageInfo.PagingCookie = entityCollection.PagingCookie;

    entityCollection = orgService.RetrieveMultiple(query);

    foreach (Entity entity in entityCollection.Entities)

    {

    memberGuids.Add(((EntityReference)entity.Attributes["entityid"]).Id);

    }

    }

    }

    public IOrganizationService GetOrganizationService()

    {

    Uri organizationUri = new Uri("servername/.../Organization.svc");

    Uri homeRealmUri = null;

    ClientCredentials credentials = new ClientCredentials();

    credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;

    OrganizationServiceProxy orgProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, null);

    IOrganizationService _service = (IOrganizationService)orgProxy;

    return _service;

    }

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at
  • Community Member Profile Picture
    on at

    Ok, thank you for all answers. I have a new problem now, i got all members but now I need to get contacts from members who are in marketing list, any ideas?

  • Suggested answer
    Rajat Awasthi Profile Picture
    675 on at

    Hi ,

    You need to get members according to your list id.

  • Verified answer
    Community Member Profile Picture
    on at

    get entityid column from list member entity. This would be the Entity Reference of contact associated with that list member.

  • Nithya Gopinath Profile Picture
    17,078 on at
  • Emre GULCAN Profile Picture
    2,379 on at

    Hi,

    You can retrieve your list members without regarding to your list type (dynamic or static) with XrmLibrary (download from NuGet)

    ListHelper helper = new ListHelper(_organizationService);
    var members = helper.GetMemberList(Guid.Parse("YOUR MARKETING LIST ID")); //this returns "ListMemberResult" class
    
    foreach (var item in members.Data)
    {
       Guid id = item.Id;
       string fullname = item.Name; //If your membertype is Contact or Lead this will be "FULLNAME", if membertype is Account this will be "NAME"
    }


  • Community Member Profile Picture
    on at

    Ok i used this code but something is wrong and i dont know what(not best at debuging) i dont get anything to Array.

    Code:

    using Microsoft.Xrm.Sdk;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.Xrm.Sdk.Query;
    using System.Collections;
    using Microsoft.Xrm.Sdk.Client;
    using System.ServiceModel.Description;
    
    
    namespace PluginMARetriveMembers
    {
        public class PlugInEvent : IPlugin
        {
            //public IOrganizationService OrganizationService { get; private set; }
    
            public void Execute(IServiceProvider serviceProvider)
            {
    
                //definition of context and services
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                IOrganizationServiceFactory servicefactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService client = servicefactory.CreateOrganizationService(context.UserId);
                IOrganizationService service = (IOrganizationService)servicefactory.CreateOrganizationService(context.UserId);
    
    
    
             
    
                ArrayList memberGuids = new ArrayList();
               // IOrganizationService orgService = OrganizationService;
                PagingInfo pageInfo = new PagingInfo();
                pageInfo.Count = 5000;
                pageInfo.PageNumber = 1;
                QueryByAttribute query = new QueryByAttribute("members");
                // GUID to static market list
                query.AddAttributeValue("listid", new Guid("9396465b-bf06-e711-80e3-3863bb358c80"));
                query.ColumnSet = new ColumnSet(true);
                EntityCollection entityCollection = service.RetrieveMultiple(query);
                Entity description = new Entity("campaign");
                description["description"] = "Tu bodo napisani memberji";
                description["descriptio"] = "Tu bodo napisani memberji";
                memberGuids.Add("Jhon Doe");
    
    
    
                foreach (Entity entity in entityCollection.Entities)
                {
                    memberGuids.Add(((EntityReference)entity.Attributes["entityid"]).Id);
                    
                }
                
                
                Console.WriteLine("!TEST!");
                // more than 5000 contacts
                while (entityCollection.MoreRecords)
                {
                    query.PageInfo.PageNumber += 1;
                    query.PageInfo.PagingCookie = entityCollection.PagingCookie;
                    entityCollection = service.RetrieveMultiple(query);
                    foreach (Entity entity in entityCollection.Entities)
                    {
                        memberGuids.Add(((EntityReference)entity.Attributes["entityid"]).Id);
                    }
                    
                }
            }
            
          
    
            }
    }
    
    
    


Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans