views:

378

answers:

1

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  A: 

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"

benjynito