D365: Unable to delete entity having hidden dependency(with Canvas App)

Recently, we were trying to delete one entity(not that heavily customized) as we wanted to use a different attirbute as Primary field from what being currently used, in our DEV instance.
We removed all possible dependency for deleting the entity by clicking on Entity -> Show Dependencies in the solution.

After removing all the dependencies, when we tried to delete the entity, we got dependency error message as below:

Clicking on Details highlighted above, we saw blank window without any dependency information as below:

Now, being confused, what to do next, desperately tried deleting the entity couple of times more but there was no luck.

After spending some more time on this, we found that there is a canvas app in which the records of this entity were being used to be populated in a dropdown. We changed the source of that dropdown to a different entity temporarily and published the canvas app.

After that when we tried to delete the entity still we got the same dependency error and we were unable to delete the entity.

We were using the canvas app on Contact form. We removed the app from the form and published it. Then, we tried to delete the entity but no luck.

Downloading the log file from the “Cannot delete component” error message, we found that we can use “RetrieveDependenciesForDeleteRequest” request to get the details of the dependency for deleting a component.

Below is the code we used to get details of the dependency:

RetrieveDependenciesForDeleteRequest retrieveDependenciesForDeleteRequest = new RetrieveDependenciesForDeleteRequest();
retrieveDependenciesForDeleteRequest.ComponentType = 1; //for Entity
// For all the component type: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/solutioncomponent?view=dynamics-ce-odata-9#properties
retrieveDependenciesForDeleteRequest.ObjectId = new Guid("b86a0c35-8d3b-4fac-b848-9f139aab20b4"); // GUID of the component to be deleted(entity in our case)
RetrieveDependenciesForDeleteResponse response = (RetrieveDependenciesForDeleteResponse)_serviceProxy.Execute(retrieveDependenciesForDeleteRequest);

Here, fortunately, we got one dependency record in the response. We used the sample at https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/gg509063(v=crm.8)?redirectedfrom=MSDN to parse the response and found that the dependency is still with the canvas app.

Digging more in the canvas app, we found that although we were not actively using the entity to be deleted(as we pointed the dropdown to a different entity temporarily mentioned above), the entity was still present in the Data sources as shown below:

Clicking the ellipsis button for more action, we removed the entity from the Data sources and published the canvas app.

Then we executed the above mentioned “RetrieveDependenciesForDeleteRequest” code and in the response we got 0 record.

After that when we tried to delete the entity, we were able to delete it successfully.

Although we deleted the entity in our case, I personally don’t prefer deleting any component once it is customized or there’s dependency unless it is created fresh and doesn’t hold any dependency with other components in the system.

Hope it helps !!

2 thoughts on “D365: Unable to delete entity having hidden dependency(with Canvas App)

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.