web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to retrieve related entity data based on entity relationships

(0) ShareShare
ReportReport
Posted on by

I'm new to CRM and for an entity I need to retrieve related entity info using the web api. I'm trying to do this based on the relationship metadata that can be retrieved using the api. For exmple I have the account entity. If I get the relationship data between entity and contact I get the following: 

    "value": [
        {
            "SchemaName": "contact_customer_accounts",
            "ReferencingEntity": "contact",
            "ReferencingAttribute": "parentcustomerid",
            "ReferencedEntity": "account",
            "ReferencedAttribute": "accountid",
            "MetadataId": "dc9b80f8-c781-46d8-9fd6-a3b610836975"
        },
        {
            "SchemaName": "account_primary_contact",
            "ReferencingEntity": "account",
            "ReferencingAttribute": "primarycontactid",
            "ReferencedEntity": "contact",
            "ReferencedAttribute": "contactid",
            "MetadataId": "410707b1-9554-4cd9-8437-6608b1802904"
        }
    ]

Based on this information I would like to retrieve the contacts for a account, so I would create a http request with someting like;

https://<my_crm_url>/api/data/v8.2/contact?$select=<some attributes>&filter=parentcustomerid eq '<account id value>'

When executing the request I get an error 'Resource not found for the segment 'contact'. When I change contact to contacts I get the error 'Could not find a property named 'parentcustomerid' on type 'Microsoft.Dynamics.CRM.contact''

What am I missing here? Can someone me please provide me some tips on how to achieve this. 

Thanks in advance!

*This post is locked for comments

I have the same question (0)
  • MV-15080823-0 Profile Picture
    on at

    In the request the &filter should be &$filter

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Check CRMRestBuilder - it will make composing of WebApi requests much easier - github.com/.../2.5.0.0

  • Suggested answer
    imayur Profile Picture
    630 on at

    Hi,

    Easiest way to create rest calls for CRM, Use REST Builder

    you need to use $expand=lookupfield_entityname(select contact fields) before $filter .

    can refer this

    /accounts?$select=accointid&$expand=new_customer_contact($select=address1_city,address1_country,address1_line1,address1_line2,address1_line3,address1_postalcode,address1_stateorprovince,fullname,entityimageid),new_customer_account($select=address1_city,address1_country,address1_line1,address1_line2,address1_line3,address1_postalcode,address1_stateorprovince,name,entityimageid)

  • CrmMad Profile Picture
    65 on at

    I had the same problem, so many POC's later.... I found that when you use web.api if the relation is uppercase and lowercase, you must put it in uppercase and lowercase and then it works !!!

    Now it will be a bug ???

    Maybe later it will change to all lowercase, ....

    Not working , Using:


    Xrm.WebApi.retrieveRecord("contact", idanimal, "?$select=fullname&$expand=why_animalpettypeId($select=why_animalpettypeid)").then(

    Using this, it's working Right!!:

    Xrm.WebApi.retrieveRecord("contact", idanimal, "?$select=fullname&$expand=why_AnimalPetTypeId($select=why_animalpettypeid)").then(

  • Suggested answer
    Willem De Backer Profile Picture
    20 on at

    the problem in youre requests is in the filter

    for lookup fields you cant use just "parentcustomerid"  thats why it says it cant find the field. 

    instead you have to use "_parentcustomerid_value".

    try this : https://<youre _crm_url/api/data/v8.2/contacts?$select=<some attributes>&$filter=_parentcustomerid_value eq '<account id value>'

     

     


    PS: you have to use 'contacts' not 'contact ' for retrieving multiple entitys.

  • Hedi Daneels Profile Picture
    487 on at

    -- please delete this post

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans