locked
Adding marketing list to campaign RRS feed

  • Question

  • Hi there,

    In our system there can be only one marketing list added to any campaign. How can i find out programatically the name/id of the marketing list if i know the campaign name/id? W

    Thanks alot!

    Sunday, May 10, 2009 2:44 AM

Answers

  • Hi.

    For reading the list of marketing lists which belong to some campaign( campaingid - is the identifier of campaign) try to use following code for query creation:

    CrmService crmService = new CrmService();
    //... CrmService creation
    
    QueryExpression expression = new QueryExpression();
    expression.ColumnSet = new AllColumns();
    expression.EntityName = EntityName.list.ToString();
    LinkEntity linktoitems = expression.AddLink(EntityName.campaignitem.ToString(),  "listid", "entityid", JoinOperator.Inner);
    linktoitems.LinkCriteria = new FilterExpression();
    ConditionExpression condition = new ConditionExpression("campaingid", ConditionOperator.Equal, campaignid);
    linktoitems.LinkCriteria.Conditions.Add(condition);
    RetrieveMultipleRequest request = new RetrieveMultipleRequest();
    request.Query = expression;
    
    RetrieveMultipleResponce responce = (RetrieveMultipleResponce)crmService.Execute(request);
    
    //in response collected all lists connected with marketing campaing


    Truth opens to prepared mind. My blog - http://a33ik.blogspot.com
    • Marked as answer by LearnQuick Monday, May 11, 2009 1:54 PM
    Sunday, May 10, 2009 5:36 AM
    Moderator

All replies

  • Hi.

    For reading the list of marketing lists which belong to some campaign( campaingid - is the identifier of campaign) try to use following code for query creation:

    CrmService crmService = new CrmService();
    //... CrmService creation
    
    QueryExpression expression = new QueryExpression();
    expression.ColumnSet = new AllColumns();
    expression.EntityName = EntityName.list.ToString();
    LinkEntity linktoitems = expression.AddLink(EntityName.campaignitem.ToString(),  "listid", "entityid", JoinOperator.Inner);
    linktoitems.LinkCriteria = new FilterExpression();
    ConditionExpression condition = new ConditionExpression("campaingid", ConditionOperator.Equal, campaignid);
    linktoitems.LinkCriteria.Conditions.Add(condition);
    RetrieveMultipleRequest request = new RetrieveMultipleRequest();
    request.Query = expression;
    
    RetrieveMultipleResponce responce = (RetrieveMultipleResponce)crmService.Execute(request);
    
    //in response collected all lists connected with marketing campaing


    Truth opens to prepared mind. My blog - http://a33ik.blogspot.com
    • Marked as answer by LearnQuick Monday, May 11, 2009 1:54 PM
    Sunday, May 10, 2009 5:36 AM
    Moderator
  • Thanks alot for you response. This is exactly what i was asking for.
    But when i am using AddLink property of LinkEntity, i am getting below error

    "Error 3 'QueryExpression' does not contain a definition for 'AddLink' and no extension method 'AddLink' accepting a first argument of type 'QueryExpression' could be found (are you missing a using directive or an assembly reference?) "

    I tried to add Microsoft.Crm.Sdk.dll assembly and Microsoft.Crm.Sdk.Query reference on the top. but does not work.

    Am i missing something?
    Sunday, May 10, 2009 2:47 PM
  • Hi, it's strange cause code works fine on my PC. Try chage code to following:

                LinkEntity linktoitems = new LinkEntity(EntityName.list.ToString(), EntityName.campaignitem.ToString(), "listid", "entityid", JoinOperator.Inner);
                linktoitems.LinkCriteria = new FilterExpression();
                ConditionExpression condition = new ConditionExpression("campaingid", ConditionOperator.Equal, campaignid);
                linktoitems.LinkCriteria.Conditions.Add(condition);
    
                QueryExpression expression = new QueryExpression();
                expression.ColumnSet = new AllColumns();
                expression.EntityName = EntityName.list.ToString();
                expression.LinkEntities.Add(linktoitems);
    
                RetrieveMultipleRequest request = new RetrieveMultipleRequest();
                request.Query = expression;


    Truth opens to prepared mind. My blog - http://a33ik.blogspot.com
    Sunday, May 10, 2009 8:47 PM
    Moderator
  • Thanks for your support!

    I am still getting errors.

    "Error 3 'LinkEntity' does not contain a constructor that takes '5' arguments"

    "Error 5 'System.Array' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?) "

    To me its looks like i am missing some assembly reference or dll???

    Thanks again !

    Sunday, May 10, 2009 10:53 PM
  • Hi. Libraries for what version of MS CRM do you use? Do you have the reference to web service in your project?
    Truth opens to prepared mind. My blog - http://a33ik.blogspot.com
    Monday, May 11, 2009 4:41 AM
    Moderator
  • I am using CRM 4.0 and i am not referencing the web services. I have created the proxy class and using that in the project.

    Monday, May 11, 2009 12:52 PM
  • Hi. It seems that your proxy classes is the problem. I use only Microsoft.Crm.Sdk and Microsoft.Crm.Sdktypeproxy libraries.
    Truth opens to prepared mind. My blog - http://a33ik.blogspot.com
    Monday, May 11, 2009 12:56 PM
    Moderator
  • Yes, thats what it seems to be like.

    Can you please confirm the location/url of wsdl for crm 4.0 in case you know?

    Thankyou so much for all your support!
    Monday, May 11, 2009 1:17 PM
  • Dont worry about it. I would go ahead referencing directly the webservices rather than spending more time on creating the proxy class.

    THANKS ALOT! It really helped.
    Monday, May 11, 2009 1:54 PM