Set Customer Type field in D365 Javascript Web API

Introduction:

This blog explains how to set Customer Type field in D365 Javascript Web API.

Problem Statement:

We get error while setting value of Account lookup on Contact in D365 Javascript Web API as below:
“An undeclared property ‘customerid’ 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.”

Solution:

We can achieve this functionality by adding suffix entity name to the schema name of the field.

Steps of Implementation:

Below code demonstrates how to set Account on Contact.

entity["parentcustomerid_account@odata.bind"] = "/accounts(" + Account_GUID + ")";

Below code demonstrates how to set Contact on Contact.

entity["parentcustomerid_contact@odata.bind"] = "/contacts(" + Contact_GUID + ")";

Note: This issue arises when lookup attribute of the entity can accept multiple types of entity references below are common examples
1. Customer on Incident
2. Customer on Contact
3. Customer type field on Custom Entity.

Conclusion:

We can resolve issue for setting Customer type field in Javascript D365 Web API by adding suffix entity name to the schema name of the field.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s