locked
Distribute campaigns only to marketing lists of type Contact RRS feed

  • Question

  • Hi,

    I am distributing the campaign programatically using the following code...

    DistributeCampaignActivityRequest req = new DistributeCampaignActivityRequest();               
                    req.CampaignActivityId = new Guid(campaignActivityID);               
                    req.TemplateId = templateID;
                    req.SendEmail = true;
                    req.Propagate = true;
                    req.OwnershipOptions = PropagationOwnershipOptions.ListMemberOwner;
                    req.Activity = new email();

    Now, what I would like to implement is...

    I need to distribute the campaign activuty only for the marketing lists of type contact. If there are multiple marketing lists of types Contact and Account then, how can I avoid distributing to marketing lists of type Account?

    -Thanks


    Perfectionist
    Monday, May 31, 2010 7:52 AM

Answers

  • Hi,

    If you know the type of the list(i.e. account, contact, lead) etc, then use RemoveItemCampaignActivity  message to first remove that PARTICULAR list and then distribute. This will remove the list from the campaign activity.

    // 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.
    RemoveItemCampaignActivityRequest remove = new RemoveItemCampaignActivityRequest();

    // Set the ID of the campaign activity.
    remove.CampaignActivityId = new Guid("2B951FBC-1C56-4430-B23B-20A1349068F3");
    // Set the ID of the campaign activity item.

    // sepcify the LIST ID below
    remove.ItemId = new Guid("2B951FBC-1C56-4430-B23B-20A1349068F3");

    // Execute the request.
    RemoveItemCampaignActivityResponse removed =
        (RemoveItemCampaignActivityResponse)service.Execute(remove);


    Muhammad Ali Khan
    http://malikhan.wordpress.com
    • Marked as answer by Perfectionist Tuesday, June 1, 2010 3:10 PM
    Monday, May 31, 2010 10:50 AM

All replies

  • Hi,

    you can use "membertype" to check the marketing list is of type contact or account.

    Hope it will help you !!!


    Mahain
    Monday, May 31, 2010 8:08 AM
    Moderator
  • if  u have the markeing list Guid, you can  reterive the Marketing List and know what kind of list is this.

    membertype Gets or sets the type of the members that can be stored in the marketing list: account, contact, or lead.


    Muhammad Ali Khan
    http://malikhan.wordpress.com
    Monday, May 31, 2010 8:10 AM
  • Using this code, it distributes campaign activity to all the marketing lists. My question is where should I specify that distribute only on this particular marketing list...

    DistributeCampaignActivityRequest req = new DistributeCampaignActivityRequest();               
                    req.CampaignActivityId = new Guid(campaignActivityID);               
                    req.TemplateId = templateID;
                    req.SendEmail = true;
                    req.Propagate = true;
                    req.OwnershipOptions = PropagationOwnershipOptions.ListMemberOwner;
                    req.Activity = new email();

    because in the DistributeCampaignRequest object there is no property specifiying that distribute only on a particular target marketing list. we can retrieve the marketing lists if we know the campaign activity ID. Even in that case, how can I specify the target marketing list for the request object?

     


    Perfectionist
    Monday, May 31, 2010 9:04 AM
  • Marketing list are added against a specific campaign activity, while you are adding the marketing list to the campaign activity you can decide whether to include accoutn list(e.g) or not.

    So while adding the list to the campaignactivity(not campaign) make sure you don't add those lists which you don't want (i.e. type account )


    Muhammad Ali Khan
    http://malikhan.wordpress.com
    Monday, May 31, 2010 9:25 AM
  • Ali,

    But, all the marketing lists are been added to the campaign activity in the CRM itself. I am just creating an interface to distribute them. So, if I have marketing lists of both contact and Account, how can I distribute to only contacts programmatically without distributing to Accounts?

    How can I exclude the marketing lists of type other than contact?

     

    -Thanks


    Perfectionist
    Monday, May 31, 2010 9:31 AM
  • Hi,

    Before distributing,you can query marketing list (list entity) by sending guid or marketing list and check it's membertype if it's member type is "1"(account) don't distribute.


    Mahain
    Monday, May 31, 2010 10:01 AM
    Moderator
  • I am querying and I know the membertype for each marketing list. Now, how can I exclude a particular list from distributing? If I say distribute, it will distribute to all the marketing lists present for that campaign activity because no where we are specifiying the marketing lists...
    Perfectionist
    Monday, May 31, 2010 10:06 AM
  • Also below the code to get member type of list based on listid

    QueryExpression query = new QueryExpression();

    query.EntityName="list";

    ColumnSet columns = new ColumnSet();
    columns.Attributes = new string[] { "membertype" };
    query.ColumnSet = columns;

    query.Criteria = new FilterExpression();
    query.Criteria.FilterOperator = LogicalOperator.And;

    ConditionExpression condition1 = new ConditionExpression();
    condition1.AttributeName = "listid";
    condition1.Operator = ConditionOperator.Equal;
    condition1.Values = new object[] { "GUID of List" };
    query.Criteria.Conditions = new ConditionExpression[] { condition1 };

     


    Mahain
    Monday, May 31, 2010 10:07 AM
    Moderator
  • I am able to get the member type for the list. But, my campaign activity and target member lists are added through crm UI. I am creating  a button to ditribute those activities.

    Now, how can I exclude a particular marketing list???


    Perfectionist
    Monday, May 31, 2010 10:36 AM
  • Hi,

    Where are you creating this ISV button ???


    Mahain
    Monday, May 31, 2010 10:40 AM
    Moderator
  • Hi Mahender,

    I am creating the button in campaign activity and trying to programmatically distribute it. Eveything like campaign activity, target marketing lists are entered through crm but, I am creating the button just to choose an email template and distribute the activity.

    -Thanks


    Perfectionist
    Monday, May 31, 2010 10:49 AM
  • Hi,

    If you know the type of the list(i.e. account, contact, lead) etc, then use RemoveItemCampaignActivity  message to first remove that PARTICULAR list and then distribute. This will remove the list from the campaign activity.

    // 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.
    RemoveItemCampaignActivityRequest remove = new RemoveItemCampaignActivityRequest();

    // Set the ID of the campaign activity.
    remove.CampaignActivityId = new Guid("2B951FBC-1C56-4430-B23B-20A1349068F3");
    // Set the ID of the campaign activity item.

    // sepcify the LIST ID below
    remove.ItemId = new Guid("2B951FBC-1C56-4430-B23B-20A1349068F3");

    // Execute the request.
    RemoveItemCampaignActivityResponse removed =
        (RemoveItemCampaignActivityResponse)service.Execute(remove);


    Muhammad Ali Khan
    http://malikhan.wordpress.com
    • Marked as answer by Perfectionist Tuesday, June 1, 2010 3:10 PM
    Monday, May 31, 2010 10:50 AM
  • If I do so, will it removes from the crm also??? I don't want to remove it permanantly but I want to exclude it from distributing.
    Perfectionist
    Monday, May 31, 2010 11:01 AM
  • No it will remove it ONLY from the campaign activity, The list will be there in MS CRM.

    The list will also be there against the campaign(for which you created the campaign activity).

    The idea here is a number of list can be added against a campaign but you can choose between the lists which one to be included with campaign activity.


    Muhammad Ali Khan
    http://malikhan.wordpress.com
    Monday, May 31, 2010 11:06 AM
  • Thanks for your assistance...It really helped me a lot.
    Perfectionist
    Monday, May 31, 2010 11:09 AM
  • So, there is no way to exclude a particular marketing list rather removing it from the campaign activity. Ok, thanks for your assistance..
    Perfectionist
    Monday, May 31, 2010 11:24 AM