Microsoft CRM, how do I get all the members of a list using CrmService?

我们两清 提交于 2019-12-23 00:28:09

问题


I am developing a tool that needs to read data from Microsoft CRM using the webservice API.

I need to get all the members of a marketing list. I can get all the lists in the system using the webservice, but I can't get the members of a list. This is the query I have so far, which I can run, but it does not return any members:

QueryExpression qe = new QueryExpression();
qe.EntityName = "contact";
qe.ColumnSet = new AllColumns();

var linkContact = new LinkEntity { 
    LinkFromEntityName = "contact", 
    LinkFromAttributeName = "contactid", 
    LinkToEntityName = "listmember",
    LinkToAttributeName = "entityid"
};  

var linkList = new LinkEntity {
    LinkFromEntityName = "listmember",
    LinkFromAttributeName = "entityid",
    LinkToEntityName = "list",
    LinkToAttributeName = "listid" };

var ce = new ConditionExpression
             {
                 AttributeName = "listid",
                 Operator = ConditionOperator.Equal,
                 Values = new object[] {list.listid.Value}
             };

linkList.LinkCriteria = new FilterExpression {Conditions = new[] {ce}};
linkContact.LinkEntities = new[] {linkList};
qe.LinkEntities = new [] {linkContact};
var members = service.RetrieveMultiple(qe);
Console.WriteLine("Members of {0}:", list.listname);
Assert.IsTrue(members.BusinessEntities.Any());

foreach(contact lead in members.BusinessEntities)
    Console.WriteLine(lead.fullname);

How can I get the members of the list using the webservice API ?


回答1:


I'm guessing you probably figured it out by now but anyway...

var linkList = new LinkEntity {
            LinkFromEntityName = "listmember",
            LinkFromAttributeName = "listid",
            LinkToEntityName = "list",
            LinkToAttributeName = "listid" };

The relevant line is:
LinkFromAttributeName = "listid", versus "entityid"



来源:https://stackoverflow.com/questions/1853500/microsoft-crm-how-do-i-get-all-the-members-of-a-list-using-crmservice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!