WebAPI Query | Dynamics CRM | Error: Property 'field' on type 'Microsoft.Dynamics.CRM.entity' is not a navigation property or complex property

Recently when I was debugging my code I got this error : Property 'field' on type 'Microsoft.Dynamics.CRM.entity' is not a navigation property or complex property'.

Basically in my WebAPI query I was requesting data from Survey entity and also I was trying to read related entity(in my case it is Incident) data values so that I don't have to do another query.

I have this 'Survey' entity and which has a lookup field called 'Regarding' (Schema name: regardingobjectid) which is a and can be related to any system defined entity.

Simply when I used regardingobjectid in my query I got error : "Could not find a property named 'regardingobjectid' on type 'Microsoft.Dynamics.CRM.msdyn_surveyinvite'." I removed this '$select' part from the url and directly run that and found that there is field called '_regardingobjectid_value' which returned guid of that 'Regarding' lookup field.

Now the new error came when I tried to get value from the related entity using this 'Regarding' lookup relation but got the error:  "Property 'regardingobjectid' on type 'Microsoft.Dynamics.CRM.entity' is not a navigation property or complex property. Only navigation properties can be expanded".Here is query url:


https://xxxxxxx.crm5.dynamics.com/api/data/v9.1 + "/msdyn_surveyinvites" + "?$select=activityid&$expand=regardingobjectid($select=_new_companycityid_value)&$filter=aie_caseregion eq " + sRegion + " and new_isSent eq false and createdon ge '" + FromDate + "' and createdon lt '" + ToDate + "' and regardingobjectid/_new_companycityid_value eq B7D6FC62-3AAE-E611-80F1-3863BB2EB860  and statuscode ne 173710009 and statuscode ne 6";



Ideally it should have worked but it was not working in my case. I even replaced that 'regardingobjectid' with '_regardingobjectid_value' but that too didn't worked as '_value' only contains guid.

To use $expand you have to use the schema name or search the 'Partner' value inside the navigation property of your entity and that too is case sensitive. Check metadata for the CRM : https://xxxxxx.crmX.dynamics.com/api/data/v9.1/$metadata



The correct URL:


 https://xxxxxxx.crm5.dynamics.com/api/data/v9.1 + "/msdyn_surveyinvites" + "?$select=activityid&$expand=regardingobjectid_incident_msdyn_surveyinvite($select=_new_companycityid_value)&$filter=aie_caseregion eq " + sRegion + " and new_isSent eq false and createdon ge '" + FromDate + "' and createdon lt '" + ToDate + "' and regardingobjectid_incident_msdyn_surveyinvite/_new_companycityid_value eq B7D6FC62-3AAE-E611-80F1-3863BB2EB860  and statuscode ne 173710009 and statuscode ne 6";



Comments

Popular posts from this blog

How to show enlarge image when mouse hover on image or link in Asp.Net(c#) using JavaScript

StateCode and StatusCode Values for mostly used entities in Microsoft Dynamics CRM 2013

Search data in Gridview on Textbox Key press event using JQuery in Asp.Net- C#

go to top image