Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Chicken and Egg problem deleting entities

Posted on by 265

We are wanting to automate the deployment of our CRM solutions as much as possible, and have a good process in place using VSTS and the solution packager. CRM customisations are kept in a customisations project in Visual Studio and our CI process builds (re-packs) the solution for deployment to other environments.


We've come across a situation where we don't think we're going to be able to automate this particular metadata change.

We have two entities in a parent -> child relationship which we want to delete.
The child records are displayed on the parent entity form in an associated view.

The manual process would be something like this.

1.) Remove the associated view from the parent form.
2.) Delete the relationship between the entities.
3.) Delete the parent entity.
4.) Delete the child entity.

We have carried out these steps in dev, and written the code to carry out steps 2-4 using the API.

However, when we export the solution from Dev for deployment to other environments, the form is now longer part of the solution, because the entities have been deleted.
This means that we cannot programatically delete the relationship between the entities, because the form in our target environment still contains the associated view.

The only options I can think of are:

Manually update the form in all of the target environments. The defeats the point of having a CI process.

Writing a script to hack the XML of the form in all of the target environments. Don't like the sound of that much, although it is doable.

Can anyone think of any other solution to this problem?

*This post is locked for comments

  • Suggested answer
    Ben Walker Profile Picture
    Ben Walker 265 on at
    RE: Chicken and Egg problem deleting entities

    Turns out that manipulating the XML is not so difficult. And as the entity is going to be deleted anyway, it's not too risky.

    Here's the code, for anyone who's interested:

    string SectionName = "Shared Records";
    string entityName = "bsp_recordshareentity";
    bool publicationNeeded = false;
    
    // Get the formxml for the entity QueryExpression formQuery = new QueryExpression { EntityName = "systemform", ColumnSet = new ColumnSet(true), Criteria = new FilterExpression { Conditions = { new ConditionExpression { AttributeName = "objecttypecode", Operator = ConditionOperator.Equal, Values = { 10058 } } } } }; EntityCollection collection = service.RetrieveMultiple(formQuery); foreach (Entity form in collection.Entities) { string formXml = form["formxml"].ToString();
    if (formXml.Contains(SectionName)) { publicationNeeded = true; Console.WriteLine("Found a section called " + SectionName + " on form"); // Remove the section from the document XmlDocument doc = new XmlDocument(); doc.LoadXml(formXml); XmlNode root = doc.DocumentElement; XmlNode node = root.SelectSingleNode("//tab[labels/label/@description='" + SectionName + "']"); root.FirstChild.RemoveChild(node); Console.WriteLine("Section node has been removed "); form["formxml"] = doc.InnerXml.ToString(); service.Update(form); } } if (publicationNeeded) { PublishXmlRequest request = new PublishXmlRequest { ParameterXml = @"<importexportxml> <entities> <entity>" + entityName + @"</entity> </entities> <nodes/> <securityroles/> <settings/> <workflows/> </importexportxml>" };
    var response = (PublishXmlResponse)service.Execute(request); Console.WriteLine("Changes to entity " + entityName + " published"); } Console.WriteLine("Finished");


  • Ben Walker Profile Picture
    Ben Walker 265 on at
    RE: Chicken and Egg problem deleting entities

    Thanks Alex. I was thinking about doing this in multiple passes, but that's not really going to work in a CI process. If the latest version of the organisation in source control does not have the entity form in it, because the entity has been deleted, you can never update the form prior to deleting the dependencies...

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Chicken and Egg problem deleting entities

    Not sure how the automation works - you might try splitting this process into multiple steps.. any time you are about to delete an entity(once you have removed all dependencies), you need to export the solution and import it to the target organizations..

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans