Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Plugin: Compare FetchXML results

Posted on by Microsoft Employee

Hi -

I have a plugin with two separate fetchXML retrievemultiple requests. Both return contacts. I want to compare the two sets. List 1 contains a list of contactids (Guids) as does List 2. I want to be able to find the differences. For example:

List 1:

1234-3456

8888-9999

List 2:

1234-3456

8888-9999

3333-3333

I want to ignore the duplicates, and just use the unique record from list 2 (3333-3333), to go and create a custom record called new_delegate, which is linked to this contact.

Any ideas how I can achieve this please?

Thanks.

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Plugin: Compare FetchXML results

    Alternatively, you may want to consider a CTI solution called Tenfold. They have a plugin for Chrome that enables call popup notes and click-to-dial. They also support MS Dynamics integration. Here's a list of their integration www.tenfold.com/.../dynamics

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Plugin: Compare FetchXML results

    This worked. Thank you Bas!

    EntityCollection List2 = service.RetrieveMultiple(new FetchExpression(fetchmlm));

               List<string> sList2 = new List<string>();

               foreach (var mlm in List2.Entities)

               {

                   sList2.Add(mlm["contactid"].ToString());

                   if(sList1.Contains(mlm["contactid"].ToString()))

                   {

                   }

                   else

                   {

                       mlm_contactid = (Guid)mlm["contactid"];

                       Entity del = new Entity("frp_eventdelegate");

                       del["frp_contact"] = new EntityReference("contact", mlm_contactid);

                       service.Create(del);

                   }

               }

  • Suggested answer
    prt33k Profile Picture
    prt33k 6,907 on at
    RE: Plugin: Compare FetchXML results
    // list1 = List of GUID
    // list2 =  list of GUID
    
    var c = list1.Where(x => !list2.Contains(x)).ToList();
    
    foreach(Guid a in c)
    {
          // Create entity
    }

    Thanks,

    PS

  • Verified answer
    Bas van de Sande Profile Picture
    Bas van de Sande 4,383 on at
    RE: Plugin: Compare FetchXML results

    Hi Rich,

    how about

    foreach (var id from secondList)

    {

     if (!firstList.Contains(id))

     {

        // do your magic

        var entity = new Entity("name of entity");

        entity["myfield"]=new EntityReference("contact",id);

         .....

     }

    }

    Is this what you're looking for

    Bas

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Plugin: Compare FetchXML results

    That has helped!

    The problem now is that if there are additional Guids in list two, I need to pass each of them into a variable to use in my create method...

  • Suggested answer
    Bas van de Sande Profile Picture
    Bas van de Sande 4,383 on at
    RE: Plugin: Compare FetchXML results

    Hi Rich,

    the way I would do this is by fetching the just the contactid's from both entities, store them in a List<Guid> and then iterate through the records in the second list by checking if the item exists in the first list.

    if (!firstList.Contains(Guid From Second List))

    {

     // do your magic

    }

    I hope this points you in the right direction

    Bas

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans