Recently, I was trying to update a record via Web API in Dynamics 365:
entity['firstname.lastname@example.org'] = contactId
However, it threw below error:
“An undeclared property ‘new_parentCustomerId’ which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values.”
I explored multiple blogs and tried to look for the solutions but everyone suggested to use Schema Name but it did not work.
Finally, after investigation, I resolved it as below:
1. Go to Settings-->Customization-->Developer Resources.
2. click on Download oData Metadata link under Instance Web API.
3. Open the Xml file downloaded in above step and search for that field.
4. You would find below line with NavigationProperty link.
<NavigationProperty Name="new_ParentCustomerId_PhoneCall" Type="mscrm.new_contactmap" Nullable="false" Partner="new_new_contactmap_account_PhoneCall">
<ReferentialConstraint Property="_new_parentcustomerid_value" ReferencedProperty="new_contactid" />
5. Based upon NavigationProperty Name xml tag, I modified the code as below to Web API update method and it worked:
entity['new_ParentCustomerId_PhoneCall@odata.bind'] = contactId
Most of the time schema name is same as Navigation Property name in metadata. However, it is not guaranteed. In my case, putting schema name worked in one case but not in other case. This led me to investigate it further and found how these Navigation Property is being used via Web API to update the lookup. Similarly to update the Customer/Regarding lookup, you can look for navigation property. However, for these type of lookup, you will find multiple Navigation Property based upon each entity. Like, for Customer lookup, there would be customerId_account and customerid_contact properties exist.