Export (0) Print
Expand All

Create a Marketing Automation List

CRM 1.2
banner art

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

[C#]
using System;
using CrmSdk;

namespace Microsoft.Crm.Sdk.HowTo
{
   /// <summary>
   /// Summary description for MarketingAutomationListCreation.
   /// </summary>
   public class MarketingAutomationListCreation
   {
      public MarketingAutomationListCreation()
      {
      }

      public static bool Run()
      {
         // Set up the CRM Service.
         CrmService service = new CrmService();
         service.Credentials = System.Net.CredentialCache.DefaultCredentials;   
         
         #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;
      }
   }
}
[Visual Basic .NET]
Imports System
Imports CrmSdk

Namespace Microsoft.Crm.Sdk.HowTo
   ' <summary>
   ' Summary description for MarketingAutomationListCreation
   ' </summary>
   
    Public Class MarketingAutomationListCreation

      Public Sub New()
      End Sub 'New

      Public Shared Function Run() As Boolean
         
         ' Set up the CRM Service.
         Dim service As New CrmService()
         service.Credentials = System.Net.CredentialCache.DefaultCredentials
         
         '---- Setup Data Required for this Sample ------------------------------
         Dim accountCreate As New account()

         accountCreate.name = "Fourth Coffee"
         accountCreate.description = "Coffee House"

         Dim createdId As Guid = service.Create(accountCreate)
         '-----------------------------------------------------------------------

         '---- Create List ------------------------------------------------------

         Dim autoList As New list()
         autoList.listname = "Test List"
         autoList.membertype = New CrmNumber()
         autoList.membertype.Value = 1
         autoList.createdfromcode = New Picklist()
         autoList.createdfromcode.Value = 1

         Dim listId As Guid = service.Create(autoList)

         '-----------------------------------------------------------------------

         '---- Add Member to List -----------------------------------------------
         Dim addRequest As New AddMemberListRequest()
         addRequest.EntityId = createdId
         addRequest.ListId = listId

         Dim response As AddMemberListResponse = _
            CType(service.Execute(addRequest), AddMemberListResponse)
         '-----------------------------------------------------------------------

         '---- check success ----------------------------------------------------

         Dim success As Boolean = False

         If Not response.Id.Equals(Guid.Empty) Then
            success = True
         End If
         '-----------------------------------------------------------------------
      
         '---- Remove Data Required for this Sample -----------------------------
         service.Delete(EntityName.account.ToString(), createdId)
         service.Delete(EntityName.list.ToString(), listId)
         '-----------------------------------------------------------------------

         Return success
      End Function 'Run
   End Class 'MarketingAutomationListCreation
End Namespace

© 2007 Microsoft Corporation. All rights reserved.


Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft