Wednesday, June 12, 2013

Create Dynamic Marketing List in CRM 2011 with C# .Net

If you want to create Dynamic Marketing List in CRM using C# please follow these steps

1. Create your Desired FetchXML using Advance Find in CRM.
2. Download that FetchXML.
3. Use that FetchXML in below code (Just replace " with ' )

your final code looks like

var service = new XrmServiceContext("Xrm");
            String fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
  <entity name='contact'>
    <attribute name='fullname' />
    <attribute name='telephone1' />
    <attribute name='contactid' />
    <order attribute='fullname' descending='false' />
    <filter type='and'>
      <condition attribute='address1_city' operator='eq' value='Florida' />
      <condition attribute='address1_country' operator='like' value='%USA%' />

            // Create dynamic list. Set the type to true to declare a dynamic list. Set CreatedFromCode to 1 for account member type.
            List dynamicList = new List()
                Type = true, //True for Dynamic List
                ListName = "Dynamic List", //Name of the List
                CreatedFromCode = 2, //1 For Account; 2 For Contact; 3 For Lead
                Query = fetchXml
            Guid _dynamicListId = service.Create(dynamicList);
Advantages: Some companies uses marketing list very frequently for example they want different marketing list just with a address1_city change for this purpose we can use .Net to develop such type of Marketing lists easily.

I hope it helps someone :)