Home > MS CRM 4.0 > Retrieve Marketinglists attached to Campaign Activity

Retrieve Marketinglists attached to Campaign Activity


FetchXml:

StringBuilder sbFetchXml = new StringBuilder();
sbFetchXml.Append("<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">");
sbFetchXml.Append("<entity name="list">");
sbFetchXml.Append("<attribute name="listname"/><attribute name="listid"/>");
sbFetchXml.Append("<order attribute="listname" descending="true"/>");
sbFetchXml.Append("<link-entity name="campaignactivityitem" from="itemid" to="listid" visible="false" intersect="true">");
sbFetchXml.Append("<link-entity name="campaignactivity" from="activityid" to="campaignactivityid" alias="aa">");
sbFetchXml.Append("<filter type="and">");
sbFetchXml.AppendFormat("<condition attribute="activityid" operator="eq" uitype="campaignactivity" value="{0}"/>", campaignActivityId);
sbFetchXml.Append("</filter>");
sbFetchXml.Append("</link-entity>");
sbFetchXml.Append("</link-entity>");
sbFetchXml.Append("</entity>");
sbFetchXml.Append("</fetch>");

string strXmlResult = service.Fetch(sbFetchXml.ToString());

QueryExpression:

ConditionExpression condActivityId = new ConditionExpression();
condActivityId.AttributeName = "activityid";
condActivityId.Operator = ConditionOperator.Equal;
condActivityId.Values = new object[] { campaignActivityId };

FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.And;
filter.Conditions = new ConditionExpression[] { condActivityId };

LinkEntity leCampaignActivity= new LinkEntity();
leCampaignActivity.LinkFromEntityName = EntityName.campaignactivityitem.ToString();
leCampaignActivity.LinkFromAttributeName = "campaignactivityid";
leCampaignActivity.LinkToEntityName = EntityName.campaignactivity.ToString();
leCampaignActivity.LinkToAttributeName = "activityid";
leCampaignActivity.LinkCriteria = filter;

LinkEntity leCampaignActivityItem = new LinkEntity();
leCampaignActivityItem.LinkFromEntityName = EntityName.list.ToString();
leCampaignActivityItem.LinkFromAttributeName = "listid";
leCampaignActivityItem.LinkToEntityName = EntityName.campaignactivityitem.ToString();
leCampaignActivityItem.LinkToAttributeName = "itemid";
leCampaignActivityItem.LinkEntities = new LinkEntity[] {leCampaignActivity};

QueryExpression query = new QueryExpression();
query.EntityName = EntityName.list.ToString();
query.ColumnSet = new AllColumns();
query.LinkEntities = new LinkEntity[] { leCampaignActivityItem };

BusinessEntityCollection bec = service.RetrieveMultiple(query);

Advertisements
Categories: MS CRM 4.0
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: