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:
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";
Wow! What an excellent article!!! It is very helpful for me. I’ve learnt a lot of things from this post, thank you. If anyone wants to learn more you can also visit https://sisayed360.blogspot.com/
ReplyDeleteWow!excellent. I have learnt a lot of things from this post. If anyone wants to learn more then go to https://sisayed360.blogspot.com/
ReplyDeleteNice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here.https://www.all-laptopbattery.com
ReplyDeleteThanks for sharing your
ReplyDeleteknowledge realted to programming
The T-Shirt At The Best Prices On The T-Shirt
ReplyDeleteAt T-Shirt At The titanium price per ounce Best Prices On The T-Shirt: The T-Shirt. titanium dive knife From $35.99 a piece. On sale at Best Price. Share titanium rimless glasses on your titanium ring blog or used ford escape titanium Facebook page