locked
Adding Contact to Marketing List Dynamically RRS feed

  • Question

  • Hi there,

    Is it possible to add the members to the Marketing list dynamically while adding them to CRM using webservices?
    or if i can set up a system job which can add them to marketing list without human intraction.

    Please let me know if this is possible.

    Thanks!
    Tuesday, April 21, 2009 7:51 PM

Answers

  • Yes you can add list members to a list dynamically.

    The code below from the SDK help file demonstrates how you add a list member to a list.

    // Set up the CRM Service.
    CrmAuthenticationToken token = new CrmAuthenticationToken();
    // You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
    token.AuthenticationType = 0; 
    token.OrganizationName = "AdventureWorksCycle";
     
    CrmService service = new CrmService();
    service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
    service.CrmAuthenticationTokenValue = token;
    service.Credentials = System.Net.CredentialCache.DefaultCredentials;

    // Create the request object.
    AddMemberListRequest add = new AddMemberListRequest();

    // Set the properties of the request object.
    add.EntityId = new Guid("b050f053-yur3-dc31-bb3a-0003ffbad37a");
    add.ListId = new Guid("C15AF217-C17E-DA11-B90F-000874DE7397");

    // Execute the request.
    AddMemberListResponse added = (AddMemberListResponse) service.Execute(add);

    http://hassanhussain.wordpress.com/
    Tuesday, April 21, 2009 8:17 PM

All replies

  • Yes you can add list members to a list dynamically.

    The code below from the SDK help file demonstrates how you add a list member to a list.

    // Set up the CRM Service.
    CrmAuthenticationToken token = new CrmAuthenticationToken();
    // You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
    token.AuthenticationType = 0; 
    token.OrganizationName = "AdventureWorksCycle";
     
    CrmService service = new CrmService();
    service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
    service.CrmAuthenticationTokenValue = token;
    service.Credentials = System.Net.CredentialCache.DefaultCredentials;

    // Create the request object.
    AddMemberListRequest add = new AddMemberListRequest();

    // Set the properties of the request object.
    add.EntityId = new Guid("b050f053-yur3-dc31-bb3a-0003ffbad37a");
    add.ListId = new Guid("C15AF217-C17E-DA11-B90F-000874DE7397");

    // Execute the request.
    AddMemberListResponse added = (AddMemberListResponse) service.Execute(add);

    http://hassanhussain.wordpress.com/
    Tuesday, April 21, 2009 8:17 PM
  • In your case you might be using crmServiceCreate to add the contact(?) to CRM and get the add.EntityId from the create response (contactid not known.):

    using System;
    
    
    
    using System.Collections.Generic;
    
    
    
    using System.Linq;
    
    
    
    using System.Text;
    
    
    
    using Import2MarketingList.CrmWebService;
    
    
    
    using System.Data.OleDb;
    
    
    
    
    
    
    
    namespace Import2MarketingList {
    
    
    
        class Program {
    
    
    
            static void Main(string[] args) {
    
    
    
                // Set up the CRM Service.
    
    
    
                CrmAuthenticationToken token = new CrmAuthenticationToken();
    
    
    
                // You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
    
    
    
                token.AuthenticationType = 0;
    
    
    
                token.OrganizationName = "<org name here>";
    
    
    
    
    
    
    
                CrmService service = new CrmService();
    
    
    
                service.Url = "http://<instance url here>/mscrmservices/2007/crmservice.asmx";
    
    
    
                service.CrmAuthenticationTokenValue = token;
    
    
    
                service.Credentials = System.Net.CredentialCache.DefaultCredentials;
    
    
    
    
    
    
    
                OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Database3.accdb;Persist Security Info=False;");
    
    
    
                OleDbCommand cmd = new OleDbCommand("Select * from newadds", conn);
    
    
    
                /*
    
    
    
                     Index	Field Name
    
    
    
                     0	FirstName
    
    
    
                     1	LastName
    
    
    
                     2	Suffix
    
    
    
                     3	address1_line2
    
    
    
                     4	address1_line1
    
    
    
                     5	address1_city
    
    
    
                     6	Address1_StateOrProvince
    
    
    
                     7	address1_postalcode
    
    
    
                     8	accountid
    
    
    
                     9	ownerid
    
    
    
                     10	src
    
    
    
                     11	donotbulkemail
    
    
    
                     12	donotbulkpostalmail
    
    
    
                     13	donotemail
    
    
    
                     14	donotfax
    
    
    
                     15	donotphone
    
    
    
                     16	donotpostalmail
    
    
    
                     17	donotsendmm
    
    
    
                */
    
    
    
    
    
    
    
                // Create the request object.
    
    
    
                AddMemberListRequest add = new AddMemberListRequest();
    
    
    
                add.ListId = new Guid("C62B8B2B-4D28-DE11-9989-001F2956DADE");
    
    
    
                CrmBoolean allow = new CrmBoolean();
    
    
    
                allow.Value = false;
    
    
    
                Owner am = new Owner();
    
    
    
                am.type = EntityName.systemuser.ToString();
    
    
    
                Customer company = new Customer();
    
    
    
                company.type = EntityName.account.ToString();
    
    
    
                int i = 1;
    
    
    
    
    
    
    
                // Execute the request.
    
    
    
                conn.Open();
    
    
    
                OleDbDataReader recs = cmd.ExecuteReader();
    
    
    
                while (recs.Read()) {
    
    
    
                    // Execute the request.
    
    
    
                    try {
    
    
    
                        // Create the contact object.
    
    
    
                        contact guy = new contact();
    
    
    
    
    
    
    
                        // Create the properties for the contact object.
    
    
    
                        guy.firstname = recs.GetString(0);
    
    
    
                        guy.lastname = recs.GetString(1);
    
    
    
                        if (!recs.IsDBNull(2))
    
    
    
                            guy.suffix = recs.GetString(2);
    
    
    
                        if (!recs.IsDBNull(3))
    
    
    
                            guy.address1_line2 = recs.GetString(3);
    
    
    
                        if (!recs.IsDBNull(4))
    
    
    
                            guy.address1_line1 = recs.GetString(4);
    
    
    
                        if (!recs.IsDBNull(5))
    
    
    
                            guy.address1_city = recs.GetString(5);
    
    
    
                        if (!recs.IsDBNull(6))
    
    
    
                            guy.address1_stateorprovince = recs.GetString(6);
    
    
    
                        if (!recs.IsDBNull(7))
    
    
    
                            guy.address1_postalcode = recs.GetString(7);
    
    
    
                        if (!recs.IsDBNull(8)) {
    
    
    
                            company.Value = recs.GetGuid(8);
    
    
    
                            guy.parentcustomerid = company;
    
    
    
                        }
    
    
    
                        am.Value = recs.GetGuid(9);
    
    
    
                        guy.ownerid = am;
    
    
    
    
    
    
    
                        guy.donotbulkemail = allow;
    
    
    
                        guy.donotbulkpostalmail = allow;
    
    
    
                        guy.donotemail = allow;
    
    
    
                        guy.donotfax = allow;
    
    
    
                        guy.donotphone = allow;
    
    
    
                        guy.donotpostalmail = allow;
    
    
    
                        guy.donotsendmm = allow;
    
    
    
    
    
    
    
                        // Create the contact in Microsoft Dynamics CRM.
    
    
    
    //                    Program.displayContact(guy);
    
    
    
                        add.EntityId = service.Create(guy);
    
    
    
                        AddMemberListResponse added = (AddMemberListResponse)service.Execute(add);
    
    
    
    
    
    
    
                        Console.Write("\r" + i++);
    
    
    
                    }
    
    
    
                    catch (System.Web.Services.Protocols.SoapException se) {
    
    
    
                        Console.WriteLine(se.Detail.OuterXml);
    
    
    
                        conn.Close();
    
    
    
                        break;
    
    
    
                    }
    
    
    
                    catch (Exception e) {
    
    
    
                        Console.WriteLine(e.Message);
    
    
    
                        Console.WriteLine(e.StackTrace);
    
    
    
                        conn.Close();
    
    
    
                        break;
    
    
    
                    }
    
    
    
                }
    
    
    
                conn.Close();
    
    
    
            }
    
    
    
    
    
    
    
            public static void displayContact(contact guy){
    
    
    
    
    
    
    
                     System.Console.Write(guy.firstname);
    
    
    
                     System.Console.Write("\t" + guy.lastname);
    
    
    
                     System.Console.WriteLine("\t" + guy.suffix);
    
    
    
                     System.Console.Write(guy.address1_line2);
    
    
    
                     System.Console.WriteLine("\t" + guy.address1_line1);
    
    
    
                     System.Console.Write("\t" + guy.address1_city);
    
    
    
                     System.Console.Write("\t" + guy.address1_stateorprovince);
    
    
    
                     System.Console.WriteLine("\t" + guy.address1_postalcode);
    
    
    
                     System.Console.WriteLine(guy.parentcustomerid.Value);
    
    
    
                     System.Console.WriteLine("-------------------------------------------" + guy.donotbulkemail.Value);
    
    
    
            }
    
    
    
        }
    
    
    
    }
    
    
    
    
    
    
    
    
    • Edited by mardukes Tuesday, April 21, 2009 9:56 PM correction
    Tuesday, April 21, 2009 9:53 PM