Thursday, May 7, 2009

Retrieve Marketing List Members

A Marketing list in CRM, can be a collection accounts or contacts or leads. Retrieving the members of a marketing list is not as as simple. We just realized that the list member entity only stores the link to the entity and Retrieve method is not supported by this entity.

Hence to retrieve the list members for a given entity we need to identify the type of entity being supported by the list i.e Leads/Accounts/Contacts and then using the link entity functionality link it with the listmember entity to get the list.

Following is the snippet of getting collection of accounts from a particular marketing list id.

//initialize QueryExpression for adding link entities
QueryExpression qe = new QueryExpression();
qe.EntityName = EntityName.account.ToString();
//Initialize columnset
ColumnSet col = new ColumnSet();

//add columns to columnset for the acc to retrieve each acc from the acc list
col.AddColumns(new string[] { "accountid", "name", "address1_line1", "address1_line2", "address1_city", "address1_stateorprovince", "address1_postalcode"});

qe.ColumnSet = col;

// link from account to listmember
LinkEntity le = new LinkEntity();
le.LinkFromEntityName =
le.LinkFromAttributeName = "accountid";
le.LinkToEntityName = EntityName.listmember.ToString();
le.LinkToAttributeName = "entityid";

//link from listmember to list
LinkEntity le2 = new LinkEntity();
le2.LinkFromEntityName = EntityName.listmember.ToString();
le2.LinkFromAttributeName = "listid";
le2.LinkToEntityName = EntityName.list.ToString();
le2.LinkToAttributeName = "listid";

// add condition for listid
ConditionExpression ce = new ConditionExpression();
ce.AttributeName = "listid";
ce.Operator = ConditionOperator.Equal;
ce.Values = new object[] { strList };//here “strList” is the marketing list id provided to this function.

//add condition to linkentity
le2.LinkCriteria = new FilterExpression();

//add linkentity2 to linkentity

//add linkentities to Query Expression which is passed for getting collection of accounts

//above query expression is passed to retrieve multiple for getting BusinessEntityCollection of accounts.
BusinessEntityCollection bec = service.RetrieveMultiple(qe);

Similarly you could link with Contacts/Leads to get the list of members from a Contact/Lead Marketing list.


  1. Hi

    Recently I've been looking for some way to do Retrieve Multiple with JavaScript and I found something like this:

    My problem is thata ALL that I have found in the web shows how to do RetriveMultiple request but I don't know how to specifie more than one conditions, look:

    "<-q1:Value xsi:type='xsd:string'>"+searchCity+"<-/q1:Value>"+

    In that example, they say SELECT field FROM contact WHERE address1_city LIKE "%@searchCity%"

    Waht I do need is something more like this:

    SELECT field FROM contact WHERE (address1_city IN("value1","value2")) AND contactid = "xxxx-xxxx-xxxx-xxx"

    Do you think you could help me? any idea of how to build this query using jscript?

    By the way, I used "-" just to can post the comment, it really does not go there.

    Thanks in advanced

  2. The requirement of yours can be done by adding following bold part to your script:

    "<-q1:ColumnSet xsi:type='q1:ColumnSet'>"+
    "<-q1:Value xsi:type='xsd:string'>"+searchCity1+"<-/q1:Value>"+
    "<-q1:Value xsi:type='xsd:string'>"+searchCity2+"<-/q1:Value>"+
    "<-q1:Value xsi:type='xsd:string'>"+searchCity3+"<-/q1:Value>"+
    " <-/q1:Condition>" +
    " <-q1:Condition>" +
    "<-q1:AttributeName> contactid <-/q1:AttributeName>" +
    "<-q1:Operator>Equal<-/q1:Operator>" +
    "<-q1:Values>" +
    "<-q1:Value xsi:type=\"xsd:string\">" + contid +
    "<-/q1:Value>" +
    "<-/q1:Values>" +
    "<-/q1:Condition>" +