Wednesday 21 June 2017

{know-how} Set a lookup value on create/update of a record using MSCRM WebApi - An undeclared property Error



Recently faced an error while creating and updating records in CRM using WebAPI. The issue was around setting a lookup value and following is the error message

An undeclared property new_primaryincident 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.


Fix:
The issue is due to the fact that whenever we set a lookup value we need use schema name and not the logical name. In my case I had to use "new_PrimaryIncident" instead of  "new_primaryincident".

Code snippet:

// code with issue
"new_primaryincident@odata.bind":"/incidents(10000000-0000-0000-0000-000000000000)" 

// code after fix
"new_PrimaryIncident@odata.bind":"/incidents(10000000-0000-0000-0000-000000000000)"

Hope this helps!

No comments:

Post a Comment