Hi,
Below is the code that we could use to retrieve the GUIDs of all the members associated to a STATIC marketing list.
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("http://servername/orgname/XRMServices/2011/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; }
Hope it helps.
Hi,
Is there anyway to retrieve members of a dynamic marketing list – ie. to retrieve the members criteria and run the same query in order to iterate through the members at that point in time?
Phil
LikeLike
thx, this help, even for CRM 2013.
but one hint, on going for lists bigger 5000
when running into while …moreRecords a NullReference occurs,… so this:
PagingInfo pageInfo = new PagingInfo();
pageInfo.Count = 5000;
pageInfo.PageNumber = 1;
should be:
query.PageInfo = new PagingInfo();
query.PageInfo.Count = 5000;
query.PageInfo.PageNumber = 1;
LikeLiked by 1 person