How to consume data entities with IsPublic disabled using OData in D365 F&O
The data entities in Dynamics 365 for Finance and Operations has 'IsPublic' property which when enabled, makes the data entity available to be consumed via OData. List of data entities exposed to Odata can be viewed using the URL - [baseURL]/data, where baseURL is the URL to access Dynamics 365 Finance and Operations.
Some of the data entities do not have this 'IsPublic' property enabled out-of-the-box and therefore not exposed for OData. This property is not editable in the extension of that entity. Following are the workaround steps to consume such data entities using OData.
Let's take 'smmProspectEntity' for example. In the screenshot below, IsPublic property for smmProspectEntity is set to No.
As a workaround, create a copy of this entity in the model and set 'IsPublic' to Yes to expose the entity for OData.
Step 1: Create a copy of the entity by clicking on 'Duplicate in project'.
Click on 'Duplicate in project', it creates a copy of the entity as shown in the screenshot below
Step 2: Rename the entity and set the property 'IsPublic' to Yes.
Also specify Public Collection Name and Public Entity Name properties which are used to access the entity using OData. For this entity, Public Collection Name and Public Entity Name are specified as 'Prospects'.
Step 3: Open Entity Code to replace references(if any) to 'smmProspectsEntity' with new name of the entity copied from 'smmProspectsEntity'. The entity can also be extended by adding new fields and logic to meet the business needs.
Step 4: Build and synchronize the project.
**Note: If you run into build errors like below, make sure that the packages containing the specific objects are referenced in your model. Add the package reference by updating model parameters from Dynamics 365 --> Model Management --> Update Model Parameters menu in Visual Studio.
Error: Path: [dynamics://DataEntityView/CustCustomerV3Entity]:On view 'CustCustomerV3Entity', the field 'PersonProfessionalTitle' refers to a nonexistent table or view named 'DirPartyBaseEntity'.
Error: A reference to 'Dynamics.AX.CaseManagement, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is required to compile this module.
Step 5: After the build is successfully completed, open browser and enter [baseURL]/data to check for 'Prospects' entity. The Prospects entity is shown as in the screenshot below.
Now, the Prospects entity can be accessed via OData.
Comments
-
This should be made into a tutorial and moved over to github where others can help refine and improve it.
*This post is locked for comments