JS

Sunday, September 12, 2021

Tips for setting lookup value of using Dynamics 365 Web API

 Working with Dynamics 365 CRM, when you set a value for lookup field, maybe you will get the error “Invalid property ‘your_field' was found in entity ‘the_entity’. ---> Microsoft.OData.ODataException: Does not support untyped value in non-open type” or error “An undeclared property ‘your_field' 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.”. This means you are not setting this field incorrectly.

The first situation is you are not using the field schema name.

The second situation is you are not setting it correctly. There are several situations with the lookup field to do this:

  • Non-activity entity/table, single lookup field (lookup to only one table)

entity[<your_schema_field_name>@odata.bind] = “/<entity_logical_name in plural>(<entity_id>)”

For example: A custom field new_account lookups to account table

entity[new_accountid@odatabind] = “/accounts(b2ce603e-5bb9-eb11-8236-0022481736ba)”

  • Activity entity/table, single lookup field

entity[<your_schema_field_name>_<ActivityName>@odata.bind] = “/<entity_logical_name in plural>(<entity_id>)”

For example:

entity[new_accountid_PhoneCall@odatabind] = “/accounts(b2ce603e-5bb9-eb11-8236-0022481736ba)”

entity[new_accountid_Task@odatabind] = “/accounts(b2ce603e-5bb9-eb11-8236-0022481736ba)" 

  • For regarding field

entity[<your_schema_field_name>_<entity_lookup_logical_name>@odata.bind] = “/<entity_logical_name in plural>(<entity_id>)”

For example:

entity[regardingobjectid_account@odatabind] = “/accounts(b2ce603e-5bb9-eb11-8236-0022481736ba)” 

No comments:

Post a Comment

Error (ESLint) i.CLIEngine is not a constructor in Visual Studio 2019

To correct the ESLint error 'i.CLIEngine is not a constructor' in Visual Studio 2019 with ESLint version 8.57.0, you can follow thes...