Skip to main content

Notifications

Microsoft Dynamics CRM forum
Suggested answer

Get members of a marketing campaign

Posted on by 55

Hi,

I need to get the accounts linked to a marketing campaign through plugin ,but i dont get any result (empty entitycollection)

code is below : 

  QueryExpression queryContrat = new QueryExpression();
                    queryContrat.EntityName = "account";
                    queryContrat.NoLock = true;
                    queryContrat.ColumnSet = new ColumnSet(true);


                    var linkListAccount = new LinkEntity("account", "listmember", "accountid", "entityid", JoinOperator.LeftOuter);
                    linkListAccount.EntityAlias = "member";
                    linkListAccount.Columns = new ColumnSet(true);
              

                    var linkListmember = new LinkEntity("listmember", "list", "listmemberid", "listid", JoinOperator.LeftOuter);
                    linkListmember.EntityAlias = "listmember";
                    linkListmember.Columns = new ColumnSet(true);

                   

                    var linkListcamapgne = new LinkEntity("list", "campaignitem", "listid", "entityid", JoinOperator.Inner);
                    linkListcamapgne.EntityAlias = "list";
                    linkListcamapgne.Columns = new ColumnSet(true);
                  

                    var linkcampagnitem = new LinkEntity("campaignitem", "campaign", "entityid", "campaignid", JoinOperator.Inner);
                    linkcampagnitem.EntityAlias = "cmitem";
                    linkcampagnitem.Columns = new ColumnSet(true);
                    linkcampagnitem.LinkCriteria.AddCondition("codename", ConditionOperator.Equal, code);

                    

                    linkListcamapgne.LinkEntities.Add(linkcampagnitem);
                    linkListmember.LinkEntities.Add(linkListcamapgne);
                    linkListAccount.LinkEntities.Add(linkListmember);
                    queryContrat.LinkEntities.Add(linkListAccount);


                    try
                    {
                        EntityCollection contrats = service.RetrieveMultiple(queryContrat);
                        if (contrats.Entities != null && contrats.Entities.Count > 0)
                        {
                            LogWebService.Log(ref _log, String.Format("Sortie de la fonction {0}", MethodBase.GetCurrentMethod()), LogWebService.LogLevel.Info);
                         return contrats;
                        }
                        else
                        {
                            LogWebService.Log(ref _log, String.Format("Sortie de la fonction {0}", MethodBase.GetCurrentMethod()), LogWebService.LogLevel.Info);
                            LogWebService.Log(ref _log, "CONTRAT_COLLECTION NULL", LogWebService.LogLevel.Info);
                            return null;
                        }

Thanks ,

  • Suggested answer
    Pradeep Rai Profile Picture
    Pradeep Rai 5,490 Super User 2024 Season 2 on at
    RE: Get members of a marketing campaign

    Hi,

    Please check below link:

     

    Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,524 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,493 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans