Create a Marketing Automation List

The following code example demonstrates how to create a Marketing Automation list and add a member to it.




using System;
using CrmSdk;
using Microsoft.Crm.Sdk.Utility;

namespace Microsoft.Crm.Sdk.HowTo
{
///
/// Summary description for MarketingAutomationListCreation.
///

public class MarketingAutomationListCreation
{
static void Main(string[] args)
{
// TODO: Change the server URL and Organization to match your CRM Server and CRM Organization
MarketingAutomationListCreation.Run("http://localhost:5555", "CRM_SDK");
}

public static bool Run(string crmServerUrl, string orgName)
{
// Set up the CRM Service.
CrmService service = CrmServiceUtility.GetCrmService(crmServerUrl, orgName);

#region Setup Data Required for this Sample
account accountCreate = new account();
accountCreate.name = "Fourth Coffee";
accountCreate.description = "Coffee House";

Guid createdId = service.Create(accountCreate);
#endregion

#region Create List

list autoList = new list();
autoList.listname = "Test List";
autoList.membertype = new CrmNumber();
autoList.membertype.Value = 1;
autoList.createdfromcode = new Picklist();
autoList.createdfromcode.Value = 1;

Guid listId = service.Create(autoList);

#endregion

#region Add Member to List
AddMemberListRequest addRequest = new AddMemberListRequest();
addRequest.EntityId = createdId;
addRequest.ListId = listId;

AddMemberListResponse response = (AddMemberListResponse) service.Execute(addRequest);
#endregion

#region check success

bool success = false;

if (response.Id != Guid.Empty)
{
success = true;
}
#endregion

#region Remove Data Required for this Sample
service.Delete(EntityName.account.ToString(), createdId);
service.Delete(EntityName.list.ToString(), listId);
#endregion

return success;
}
}
}