Skip to main content
Post a question

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

FetchXML Query to get contacts Associated to Accounts

Posted on 14 Mar 2022 13:29:44 by 5

Hi All,

Can anyone please help in how to get the top 1 contact associated with each Account. An account can have more than 1 contact so I wanted to get only 1 contact for each account using FetchXml. 

Thanks in Advance!

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on 16 Mar 2022 at 03:11:31
    RE: FetchXML Query to get contacts Associated to Accounts

    Hi prasanna05,

    As Guido Preite says, only through fetchxml can't achieve this because "top" or "page" "count" can't work on child record. You could refer to this thread:    

    https://stackoverflow.com/questions/22096633/auto-numbering-to-parent-and-child-columns 

    In this thread, he achieved this by indexing the entity record.

  • prasanna05 Profile Picture
    prasanna05 5 on 15 Mar 2022 at 15:23:05
    RE: FetchXML Query to get contacts Associated to Accounts

    Thank you. I am not sure how it works, will check.

  • Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on 14 Mar 2022 at 14:54:50
    RE: FetchXML Query to get contacts Associated to Accounts

    if you need to use SSRS I would look to apply a filter after you retrieve the dataset, I know it's not ideal but with FetchXML (afaik) is not possible to limit the related records

  • prasanna05 Profile Picture
    prasanna05 5 on 14 Mar 2022 at 14:27:52
    RE: FetchXML Query to get contacts Associated to Accounts

    Thank you for the reply. Need in FetchXml as we need to use in SSRS report.

  • Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on 14 Mar 2022 at 14:00:32
    RE: FetchXML Query to get contacts Associated to Accounts

    I am not aware of doing it with FetchXML but it can be done with Web API if you apply the $top to the expand with a specific syntax (; instead of &)

    the query is something like this:

    /api/data/v9.2/accounts?$select=name&$expand=contact_customer_accounts($select=contactid,fullname;$top=1)

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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans