Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

RetrieveDependenciesForDeleteRequest not finding all dependencies for relationship

Posted on by 265

I am trying to programmatically delete a relationship between two entities using a DeleteRelationshipRequest.

The request is failing with this error:

"The EntityRelationship(7d6c9bcb-bcfa-e211-bb16-005056930383) component cannot be deleted because it is referenced by 2 other components. For a list of referenced components, use the RetrieveDependenciesForDeleteRequest."

However, using the RetrieveDependenciesForDeleteRequest returns no dependencies.

When I try and delete through the front end, it fails and shows me that there are two dependencies - one is a system view, and one is a process.

Why does my RetrieveDependenciesForDeleteRequest not find these dependencies?

Here's the code I am using:

private void CheckRelationshipDependencies(string relationshipName, IOrganizationService service)
{
	RetrieveRelationshipRequest rrreq = new RetrieveRelationshipRequest { Name = relationshipName };
	RetrieveRelationshipResponse rrresp = (RetrieveRelationshipResponse)service.Execute(rrreq);

	if (rrresp.RelationshipMetadata.SchemaName != null) {
	Console.WriteLine("Found relationship with schema name " + rrresp.RelationshipMetadata.SchemaName + " and ID " + rrresp.RelationshipMetadata.MetadataId);
	}

	Guid? relationshipID = rrresp.RelationshipMetadata.MetadataId;
	Console.WriteLine("Fetching dependencies for relationship " + relationshipID);	

	RetrieveDependenciesForDeleteRequest retrieveDependenciesForDeleteRequest = new RetrieveDependenciesForDeleteRequest
	{
		ComponentType = 3, // 3 = RELATIONSHIP msdn.microsoft.com/.../gg328546(v=crm.7).aspx
		ObjectId = (Guid)relationshipID
	};

	RetrieveDependenciesForDeleteResponse retrieveDependenciesForDeleteResponse =
	 (RetrieveDependenciesForDeleteResponse)service.Execute(retrieveDependenciesForDeleteRequest);	 	 

	Console.WriteLine("Found " + retrieveDependenciesForDeleteResponse.EntityCollection.Entities.Count + " dependencies");
	
}

and here's the output:

Found relationship with schema name bsp_college_bsp_student and ID 7d6c9bcb-bcfa-e211-bb16-005056930383
Fetching dependencies for relationship 7d6c9bcb-bcfa-e211-bb16-005056930383
Found 0 dependencies

*This post is locked for comments

  • Ben Walker Profile Picture
    Ben Walker 265 on at
    RE: RetrieveDependenciesForDeleteRequest not finding all dependencies for relationship

    In fact, even the 'Show dependencies' action in the front end does not show any dependencies, but when you try and delete the relationship it fails, and only then does it actually show the dependencies which are preventing the deletion.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans