Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

FetchXML Query to get contacts Associated to Accounts

(0) ShareShare
ReportReport
Posted on 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
    on at
    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
    5 on at
    RE: FetchXML Query to get contacts Associated to Accounts

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

  • Guido Preite Profile Picture
    54,077 Moderator on at
    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
    5 on at
    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
    54,077 Moderator on at
    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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,261 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,996 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans