4

I have an entity called as medicalcase

Each medical case has a subgrid, N:N relationship with an entity called as mcfamily

Each mcfamily has Father, Mother, Child fields which are lookups to contact field

Now if I make a webapi call

http://serverurl/api/data/v8.0/new_medicalcase(caseid)?$expand=new_medcase_mcfamily

I get the new_father_value, but I want to expand the Father lookup and get the contact name. How can I do it?

I tried

http://serverurl/api/data/v8.0/new_medicalcase(caseid)?$expand=new_medcase_mcfamily($expand=new_father($select=fullname))

But it said

navigation property can't be expanded. Multiple levels of expansion aren't supported.

Ronald Wildenberg
  • 31,634
  • 14
  • 90
  • 133
Vignesh Subramanian
  • 7,161
  • 14
  • 87
  • 150

1 Answers1

4

You'll have to manually expand by making a second request for the father contact.

If you make the request using a FetchXml query, you should be able to double-expand with one call. Here's an example of how to send a fetch query via the WebAPI (too long to copy here).

Update in response to your comment

Here's a fetch query that would retrieve all of your father names in one call. It assumes the following logical names:

  • medicalcase entity: new_medicalcase
  • mcfamily entity: new_mcfamily
    • lookup to father contact: new_fatherid
  • N:N entity: new_medicalcase_new_mcfamily
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
  <entity name="contact" >
    <attribute name="fullname" />
    <link-entity name="new_mcfamily" from="new_fatherid" to="contactid">
      <link-entity name="new_medicalcase_new_mcfamily" from="new_mcfamilyid" to="new_mcfamilyid" intersect="true">
        <link-entity name="new_medicalcase" from="new_medicalcaseid" to="new_medicalcaseid">
          <filter>
            <condition attribute="new_medicalcaseid" operator="eq" value="FAEEE5D8-D67C-E511-80E6-3863BB3CA578" />
          </filter>
        </link-entity>
      </link-entity>
    </link-entity>
  </entity>
</fetch>

To get the query working right, use the FetchXml Tester tool that comes with the XrmToolbox. After you get it working correctly, reference the link from earlier in my answer to execute the fetch query using the WebAPI.

Polshgiant
  • 3,595
  • 1
  • 22
  • 25
  • yeah that is what I have done now $(eachEntryInSubgrid) I am making an ajax call and pushing results to the array then in that case if there are 10 entries in the subgrid, there will be 10 ajax calls made isn't there a way around for this? or is this the only option available? – Vignesh Subramanian Apr 21 '16 at 06:01