locked
Use a subgrid to show which campaigns a contact has been involved in RRS feed

  • Question

  • I would like to display a subgrid on my Contact form that will contain the campaign information for the particular contact - name/date of campaigns they have been added to. Could anybody please tell me how to go about doing this?

    thanks in advance

    Monday, May 13, 2013 11:45 AM

Answers

  • There isn't a direct relationship between the campaign and the contact record, this is why you can't add a campaign subgrid on the contact record directly. The associated view is able to cope with this special relationship but the subgrids aren't quite as advanced (I've written about a similar subgrid limitation related to activities).

    You can try using a subgrid with the marketing lists instead, as shown below. If you were using only one-off marketing lists that belong to a single campaign, you could probably add a custom relationship between the lists and campaigns to draw related fields from the parent campaign into the view. For lists used across several campaigns this wouldn't work of course.


    Jukka Niiranen - My blog: Surviving CRM - Follow @jukkan on Twitter

    • Proposed as answer by VidhiyaM Tuesday, May 14, 2013 4:44 AM
    • Marked as answer by Rm_S Tuesday, May 14, 2013 5:41 PM
    Monday, May 13, 2013 8:16 PM

All replies

  • Hi,

    Try this link,

    http://thecrmworld.wordpress.com/2011/06/08/how-to-add-subgrid-in-form-of-related-records-in-crm-2011/

    Where

    Change entity as campaign from account 

    and view as of your scenario


    VidhyaM


    • Edited by VidhiyaM Monday, May 13, 2013 11:53 AM
    Monday, May 13, 2013 11:53 AM
  • try this. It might help you.


    puja jain

    • Proposed as answer by Puja Jain Monday, May 13, 2013 12:55 PM
    Monday, May 13, 2013 12:55 PM
  • I tried both of these things but nothing is showing up in the subgrid when I click on a contact that is linked to a particular campaign. any ideas? thanks
    Monday, May 13, 2013 1:00 PM
  • It will definitely show related records.

    Check your data is in which view.


    puja jain

    • Proposed as answer by Puja Jain Monday, May 13, 2013 1:03 PM
    Monday, May 13, 2013 1:02 PM
  • I have checked all views and nothing is showing up. I have set up the marketing list with contact - added this to campaign and this information shows up i the related entities associated view but not in the subgrid?

    thanks

    Monday, May 13, 2013 2:27 PM
  • There isn't a direct relationship between the campaign and the contact record, this is why you can't add a campaign subgrid on the contact record directly. The associated view is able to cope with this special relationship but the subgrids aren't quite as advanced (I've written about a similar subgrid limitation related to activities).

    You can try using a subgrid with the marketing lists instead, as shown below. If you were using only one-off marketing lists that belong to a single campaign, you could probably add a custom relationship between the lists and campaigns to draw related fields from the parent campaign into the view. For lists used across several campaigns this wouldn't work of course.


    Jukka Niiranen - My blog: Surviving CRM - Follow @jukkan on Twitter

    • Proposed as answer by VidhiyaM Tuesday, May 14, 2013 4:44 AM
    • Marked as answer by Rm_S Tuesday, May 14, 2013 5:41 PM
    Monday, May 13, 2013 8:16 PM
  • If anyone else is reading this, it can be done with a multiple retrieve plugin.

    Firstly you need to add a lookup on campaign to customer. This attribute will never contain data and will never be displayed.

    Once you have this, Campaign will appear in the available subgrids, however this grid would always be empty

    Now in a pre retrieve multiple for campaign you can do the following....

    Check if we have a condition which includes the contact (if not, this is not the subgrid so return)

    If we do, manipulate the query to return campaigns for the contact

    here is my code...

      var query = (QueryExpression)localContext.PluginExecutionContext.InputParameters["Query"];
                    query.ColumnSet.Columns.Clear();
                    query.Criteria.Conditions.Clear();
                    query.ColumnSet.AddColumn("name");
                    query.ColumnSet.AddColumn("statuscode");
                    var contact = GetClientID(query.LinkEntities);
                    query.LinkEntities.Clear();
                    query.Criteria.Filters.Clear();
                    LinkEntity link = new LinkEntity(Campaign.EntityLogicalName, CampaignItem.EntityLogicalName, Campaign.AttributeNames.CampaignId, CampaignItem.AttributeNames.CampaignId, JoinOperator.Inner);
                    LinkEntity linkInner1 = new LinkEntity(CampaignItem.EntityLogicalName, List.EntityLogicalName, CampaignItem.AttributeNames.EntityId, List.AttributeNames.ListId, JoinOperator.Inner);
                    LinkEntity linkInner2 = new LinkEntity(List.EntityLogicalName, ListMember.EntityLogicalName, List.AttributeNames.ListId, ListMember.AttributeNames.ListId, JoinOperator.Inner);
                    LinkEntity linkInner3 = new LinkEntity(ListMember.EntityLogicalName, Contact.EntityLogicalName, ListMember.AttributeNames.EntityId, Contact.AttributeNames.ContactId, JoinOperator.Inner);
                    ConditionExpression condition = new ConditionExpression(Contact.AttributeNames.ContactId, ConditionOperator.Equal);
                    condition.Values.Add(contact);
                    linkInner3.LinkCriteria.AddCondition(condition);
                    linkInner2.LinkEntities.Add(linkInner3);
                    linkInner1.LinkEntities.Add(linkInner2);
                    link.LinkEntities.Add(linkInner1);
                    query.LinkEntities.Add(link);
                    query.PageInfo = null;
    

    Now the grid will show campaigns for the contact :-)

    Remember though there are 2 campaign types, campaigns and quick campaigns this example is for campaigns but you could do a similar thing for quick campaigns

    Chris

    Saturday, July 23, 2016 10:58 AM