Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Fetch related entities on delete operation

(0) ShareShare
ReportReport
Posted on by 140

Hi,

I need to fetch related entity records of contact in a plugin on DELETE operation.

Contact and its related entities are having 1:N relationship of Parental behaviour.

Is there any way to fetch related records on delete event without changing the relationship behaviour.

TIA.

*This post is locked for comments

  • AnthonyD Profile Picture
    40 on at
    RE: Fetch related entities on delete operation

    Hello,

    I have the same issue but in my case it's a N:N relation. When deleting the parent record i want to retrieve the related records for some calculations. I have the delete operation and have it on Pre-Validation.

    However when I run this code which usually works I retrieve 0 entities.

    var query = new QueryExpression()
                    {
                        //Set this to the entity you wish to retrieve data from
                        EntityName = "cref8_cursist",
    
                        //This will return us all columns for each record returned
                        ColumnSet = new ColumnSet(true),
                    };
    
                    //AddLink(RELATIONSHIP ENTITY NAME, ENTITY UNIQUE ID FROM THE ENTITIE YOU WISH TO RETRIEVE DATA FROM, ENTITY UNIQUE ID FROM THE ENTITIE YOU WISH TO RETRIEVE DATA FROM
                    var link = query.AddLink("cref8_extrakost_cref8_cursist", "cref8_cursistid", "cref8_cursistid");
                    link.LinkCriteria = new FilterExpression()
                    {
                        //Add this to filter the Trainee records for a specified Course
                        Conditions =
                                        {
                                            new ConditionExpression("cref8_extrakostid", ConditionOperator.Equal, extraKostEntity.Id)
                                        }
                    };
    
                    //Invoke the service with our query
                    var Cursists = service.RetrieveMultiple(query);

    How did you fix this?

    Best Regards,

    Anthony

  • Suggested answer
    snehaln676 Profile Picture
    140 on at
    RE: Fetch related entities on delete operation

    Yes it works! But as pre-validation does not store any transaction, need to get values in shared variables and can use it in pre/post operation to achieve functionality.

    Thank you!

  • Verified answer
    Rawish Kumar Profile Picture
    13,756 on at
    RE: Fetch related entities on delete operation

    looks like this issue : community.dynamics.com/.../crm-plugins-retrieve-children-during-delete

    see this and let me if changing this works.

  • snehaln676 Profile Picture
    140 on at
    RE: Fetch related entities on delete operation

    Hi Rawish,

    Thank you.

    I have already tried with pre-operation plugin on Delete to retrieve related records, but its not working. Retreived records count is appearing as 0.

  • Suggested answer
    Rawish Kumar Profile Picture
    13,756 on at
    RE: Fetch related entities on delete operation

    You have to write a plugin on "Pre-Operation" Message of "Delete" Action.

    take the current record id and create queryattribute/queryexpression to retrieve all records where parent record is == current record id.

    here are some examples :  community.dynamics.com/.../245874

    www.inogic.com/.../retrieve-related-entity-records-along-wih-the-primary-entity-using-retrieve-method  

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,865 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,723 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans